From 872845f0d439b57649400e3939682f54da8f61cc Mon Sep 17 00:00:00 2001 From: ezri Date: Tue, 29 Oct 2024 14:16:18 -0400 Subject: [PATCH] Named tmpfiles (#180) * name try's tmpfiles with current time as ID for uniqueness --- try | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/try b/try index 64495aa..5774ae3 100755 --- a/try +++ b/try @@ -9,6 +9,8 @@ TRY_VERSION="0.2.0" TRY_COMMAND="${0##*/}" +EXECID="$(date +%s%3N)" +export EXECID export TRY_COMMAND # exit status invariants @@ -35,7 +37,7 @@ try() { ! [ -d "$SANDBOX_DIR" ] && { error "could not find sandbox directory $SANDBOX_DIR" 2; } else ## Create a new sandbox if one was not given - SANDBOX_DIR=$(mktemp -d) + SANDBOX_DIR=$(mktemp -d --suffix ".try-$EXECID") fi ## If the sandbox is not valid we exit early @@ -48,7 +50,7 @@ try() { ## because we have already checked if it valid. export SANDBOX_DIR - try_mount_log="$(mktemp)" + try_mount_log="$(mktemp --suffix ".try-$EXECID")" export try_mount_log # If we're in a docker container, we want to mount tmpfs on sandbox_dir, #136 @@ -64,14 +66,14 @@ try() { mkdir -p "$SANDBOX_DIR/upperdir" "$SANDBOX_DIR/workdir" "$SANDBOX_DIR/temproot" ## Find all the directories and mounts that need to be mounted - DIRS_AND_MOUNTS="$(mktemp)" + DIRS_AND_MOUNTS="$(mktemp --suffix ".try-$EXECID")" export DIRS_AND_MOUNTS find / -maxdepth 1 >"$DIRS_AND_MOUNTS" findmnt --real -r -o target -n >>"$DIRS_AND_MOUNTS" sort -u -o "$DIRS_AND_MOUNTS" "$DIRS_AND_MOUNTS" # Calculate UPDATED_DIRS_AND_MOUNTS that contains the merge arguments in LOWER_DIRS - UPDATED_DIRS_AND_MOUNTS="$(mktemp)" + UPDATED_DIRS_AND_MOUNTS="$(mktemp --suffix ".try-$EXECID")" export UPDATED_DIRS_AND_MOUNTS while IFS="" read -r mountpoint do @@ -122,9 +124,9 @@ try() { chmod "$(stat -c %a /)" "$SANDBOX_DIR/temproot" - mount_and_execute="$(mktemp)" - chroot_executable="$(mktemp)" - script_to_execute="$(mktemp)" + mount_and_execute="$(mktemp --suffix ".try-$EXECID")" + chroot_executable="$(mktemp --suffix ".try-$EXECID")" + script_to_execute="$(mktemp --suffix ".try-$EXECID")" export chroot_executable export script_to_execute @@ -225,7 +227,7 @@ do ## We can ignore this mountpoint, if the user program tries to use it, it will crash, but if not we can run normally printf "%s: Warning: Failed mounting $mountpoint as an overlay and mergerfs or unionfs not set and could not be found, see \"$try_mount_log\"\n" "$TRY_COMMAND" >&2 else - merger_dir=$(mktemp -d) + merger_dir=$(mktemp -d --suffix ".try-$EXECID") ## Create a union directory "$UNION_HELPER" $mountpoint $merger_dir 2>>"$try_mount_log" || @@ -610,7 +612,7 @@ EOF NO_COMMIT="interactive" # Includes all patterns given using the `-i` flag; will be used with `grep -f` -IGNORE_FILE="$(mktemp)" +IGNORE_FILE="$(mktemp --suffix ".try-$EXECID")" while getopts ":yvnhxi:D:U:L:" opt do