Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 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
Empty file added test/try
Empty file.
26 changes: 23 additions & 3 deletions try
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ make_overlay() {
sandbox_dir="$1"
lowerdirs="$2"
overlay_mountpoint="$3"
mount -t overlay overlay -o userxattr -o "lowerdir=$lowerdirs,upperdir=$sandbox_dir/upperdir/$overlay_mountpoint,workdir=$sandbox_dir/workdir/$overlay_mountpoint" "$sandbox_dir/temproot/$overlay_mountpoint"
mount -t overlay overlay -o userxattr -o "lowerdir=$lowerdirs,upperdir=$sandbox_dir/upperdir/$overlay_mountpoint,workdir=$sandbox_dir/workdir/$overlay_mountpoint,index=off" "$sandbox_dir/temproot/$overlay_mountpoint"
}

check_fstype() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
check_fstype() {
mountable_without_mergerfs() {

mountpoint="$1"
fstype=$(stat -f -c %T "$mountpoint")

if [[ "$fstype" = "msdos" || "$fstype" = "exfat" || "$fstype" = "hfs" || "$fstype" = "hfs+" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[ ... ]] is a bashism. but also, if COND; then return 1; fi return 0 is really just ! COND. To save on processes, we probably want:

Suggested change
if [[ "$fstype" = "msdos" || "$fstype" = "exfat" || "$fstype" = "hfs" || "$fstype" = "hfs+" ]]; then
case "$fstype" in
(msdos|exfat|hfs|hfs+) returrn 1;;
(*) return 0;;
esac

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an exhaustive list? Can we not do it for ext3/4?

return 1
fi

return 0
}


Expand Down Expand Up @@ -225,9 +236,18 @@ do
esac

# Try mounting everything normally
make_overlay "$SANDBOX_DIR" "$mountpoint" "$pure_mountpoint" 2>>"$try_mount_log"
# If the fstype is valid we mount everything

fs_fail_flag=0

if check_fstype "$pure_mountpoint"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if check_fstype "$pure_mountpoint"; then
if ! mountable_without_mergerfs "$pure_mountpoint"
then
needs_mergerfs=1
fi

And then... we ought to break out early. If any mount requires a mergerfs, we should give up early and just use mergerfs. Right?

make_overlay "$SANDBOX_DIR" "$mountpoint" "$pure_mountpoint" 2>>"$try_mount_log"
else
fs_fail_flag=1
fi

# If mounting everything normally fails, we try using either using mergerfs or unionfs to mount them.
if [ "$?" -ne 0 ]
if [[ "$?" -ne 0 || "$fs_fail_flag" -ne 0 ]]
then
## If the overlay failed, it means that there is a nested mount inside the target mount, e.g., both `/home` and `/home/user/mnt` are mounts.
## To address this, we use unionfs/mergerfs (they support the same functionality) to show all mounts under the target mount as normal directories.
Expand Down
Loading