Skip to content

Commit d474bbb

Browse files
committed
Update AppRun.sharun.ovfsProto
Signed-off-by: xplshn <anto@xplshn.com.ar>
1 parent 881319d commit d474bbb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

assets/AppRun.sharun.ovfsProto

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,25 @@ _dirname() { # DIRNAME but made entirely in POSIX SH
8080
UNIONFS_DIR="$(_dirname "$APPDIR")/unionfs"
8181
mkdir -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"
85102
MOUNT_DIR="$TEMP_DIR/mount_dir"
86103
mkdir -p "$MOUNT_DIR"
87104

0 commit comments

Comments
 (0)