libmakepkg: when checking for write permissions, handle pre-existing dirs

Simplifies the function a bit, but mostly, mkdir -p will never fail if
the directory exists, and therefore makepkg never checks to see if it is
actually writable. On the other hand, it's unnecessary to check if the
directory exists once we know mkdir -p succeeded...

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Eli Schwartz 2018-05-30 22:50:23 -04:00 committed by Allan McRae
parent 9eb3695a3f
commit c37a06fe1d

View file

@ -86,12 +86,12 @@ ensure_writable_dir() {
local dirtype="$1" dirpath="$2"
if ! mkdir -p "$dirpath" 2>/dev/null; then
if [[ -d $dirpath && ! -w $dirpath ]]; then
error "$(gettext "You do not have write permission for the directory \$%s (%s).")" "$dirtype" "$dirpath"
else
error "$(gettext "Failed to create the directory \$%s (%s).")" "$dirtype" "$dirpath"
fi
error "$(gettext "Failed to create the directory \$%s (%s).")" "$dirtype" "$dirpath"
return 1
elif [[ ! -w $dirpath ]]; then
error "$(gettext "You do not have write permission for the directory \$%s (%s).")" "$dirtype" "$dirpath"
return 1
fi
return 0
}