summaryrefslogtreecommitdiffstats
path: root/scripts/libmakepkg
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/libmakepkg')
-rw-r--r--scripts/libmakepkg/util/util.sh.in17
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/libmakepkg/util/util.sh.in b/scripts/libmakepkg/util/util.sh.in
index 7ccd2f8c..f9af5f32 100644
--- a/scripts/libmakepkg/util/util.sh.in
+++ b/scripts/libmakepkg/util/util.sh.in
@@ -83,3 +83,20 @@ cd_safe() {
exit 1
fi
}
+
+# Try to create directory if one does not yet exist. Fails if the directory
+# exists but has no write permissions, or if there is an existing file with
+# the same name.
+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
+ return 1
+ fi
+ return 0
+}