diff mbox

[pacman-dev] libmakepkg: when checking for write permissions, handle pre-existing dirs

Message ID 20180531025025.13047-1-eschwartz@archlinux.org
State Accepted, archived
Headers show

Commit Message

Eli Schwartz May 31, 2018, 2:50 a.m. UTC
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>
---
 scripts/libmakepkg/util/util.sh.in | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/scripts/libmakepkg/util/util.sh.in b/scripts/libmakepkg/util/util.sh.in
index c2f9c624..e1ca5cb7 100644
--- a/scripts/libmakepkg/util/util.sh.in
+++ b/scripts/libmakepkg/util/util.sh.in
@@ -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
 }