Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named tmpfiles #180

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions try
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

TRY_VERSION="0.2.0"
TRY_COMMAND="${0##*/}"
EXECID="$(date +%s%3N)"
export EXECID
export TRY_COMMAND

# exit status invariants
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" ||
Expand Down Expand Up @@ -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
Expand Down