fix: test_writable should fail for empty paths

This prevents attempting to create files in `/` if a path is not given, instead failing early.
This commit is contained in:
aarondill 2024-01-23 03:35:50 -06:00
parent 8c8a0cf709
commit 1d875d3abb
1 changed files with 4 additions and 1 deletions

View File

@ -466,7 +466,10 @@ elevate_priv() {
# Test if a location is writeable by trying to write to it. Windows does not let
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
test_writeable() {
path="${1:-}/test.txt"
if [ -z "${1-}" ]; then
return 1 # an empty path should never be writeable
fi
path="$1/test.txt"
if touch "${path}" 2>/dev/null; then
rm "${path}"
return 0