Skip to content

Commit

Permalink
Make mounts overlay existing content instead of moving
Browse files Browse the repository at this point in the history
Allows to operate in read-only context.
Also mitigates any possible destructive actions.
  • Loading branch information
HanabishiRecca committed Nov 14, 2023
1 parent da98242 commit 7181e27
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions caches-manager
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ make_mount() {
return 13
fi

if [ -L "$1" ]; then
unlink "$1"
elif [ -d "$1" ]; then
is_not_empty "$1" && backup "$1"
else
backup "$1"
if [ ! -d "$1" ]; then
echo "the target is not a directory, skip."
return 1
fi

mkdir -p "$1"
is_not_empty "$1" &&
echo -n "(warning: the directory is not empty, existing content will be overlayed) "

mount -t tmpfs -o "rw,$(stat -c 'mode=%a,uid=%u,gid=%g' "$1")" tmpfs "$1"
}

Expand Down Expand Up @@ -72,11 +71,6 @@ create_cache() {
return 0
fi

if [ ! -w "${parent}" ]; then
echo "no write access to parent directory, skip."
return 0
fi

if mountpoint -q "${dir}"; then
echo "mount point found, skip."
return 0
Expand All @@ -85,6 +79,10 @@ create_cache() {
if [ "$3" == "b" ]; then
make_mount "${dir}" || return 0
else
if [ ! -w "${parent}" ]; then
echo "no write access to parent directory, skip."
return 0
fi
make_link "$1" "${dir}" || return 0
fi

Expand Down

0 comments on commit 7181e27

Please sign in to comment.