File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -80,8 +80,25 @@ _dirname() { # DIRNAME but made entirely in POSIX SH
8080UNIONFS_DIR=" $( _dirname " $APPDIR " ) /unionfs"
8181mkdir -p " $UNIONFS_DIR "
8282
83- # Create temp directories for unionfs
84- TEMP_DIR=" $( mktemp -d) "
83+ TEMP_DIR=$( mktemp -d " ${TMPDIR:-/ tmp} /$name " 2> /dev/null) || unset TEMP_DIR
84+ if [ -z " $TEMP_DIR " ]; then
85+ base=" ${TMPDIR:-/ tmp} /.doNotDelete_youWillLoseHOME_$$ "
86+ n=0
87+ while true ; do
88+ TEMP_DIR=" ${base} _${n} "
89+ # mkdir is atomic in POSIX when used like this
90+ mkdir " $TEMP_DIR " 2> /dev/null && break
91+ n=$(( n + 1 ))
92+ # Sanity limit — if we ever hit this, something is horribly wrong
93+ [ " $n " -gt 5 ] && { echo " Cannot create temp dir" >&2 ; exit 1; }
94+ done
95+ fi
96+ [ -d " $TEMP_DIR " ] || { echo " Failed to create temporary directory" >&2 ; exit 1; }
97+
98+ printf ' %s\n' \
99+ " DANGER: This directory contains a symlink or bind-mount to your HOME." \
100+ " Deleting it with rm -rf will destroy your personal files." \
101+ > " $TEMP_DIR /DO_NOT_DELETE_OR_YOU_WILL_LOSE_YOUR_HOME"
85102MOUNT_DIR=" $TEMP_DIR /mount_dir"
86103mkdir -p " $MOUNT_DIR "
87104
You can’t perform that action at this time.
0 commit comments