From e8ead8f615d0ffe1cbf6fca4028ca2faf0acff9e Mon Sep 17 00:00:00 2001 From: Ezri Zhu Date: Tue, 29 Oct 2024 02:00:19 -0400 Subject: [PATCH] add time as exec id in suffix --- try | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/try b/try index 43b5b88..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 try.XXXXXXXXXX) + 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.XXXXXXXXXX)" + 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 try.XXXXXXXXXX)" + 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 try.XXXXXXXXXX)" + 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 try.XXXXXXXXXX)" - chroot_executable="$(mktemp try.XXXXXXXXXX)" - script_to_execute="$(mktemp try.XXXXXXXXXX)" + 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 try.XXXXXXXXXX) + 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 try.XXXXXXXXXX)" +IGNORE_FILE="$(mktemp --suffix ".try-$EXECID")" while getopts ":yvnhxi:D:U:L:" opt do