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

hide files/dirs #183

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions docs/try.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ This option is recommended in case OverlayFS fails.

: Specify a colon-separated list of directories to be used as lower directories for the overlay, formatted as "dir1:dir2:...:dirn" (implies -n).

-E *PATHS*

: Specify files to exclude from the sandbox, formatted as "file1:file2:...:filen".


## Subcommands

Expand Down
25 changes: 25 additions & 0 deletions test/excl_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}"
TRY="$TRY_TOP/try"

cleanup() {
cd ..

if [ -d "$try_workspace" ]
then
rm -rf "$try_workspace" >/dev/null 2>&1
fi
}

trap 'cleanup' EXIT

# try -E fails in /tmp on too many overlays
try_workspace="$(mktemp -d -p .)"

cd "$try_workspace" || exit 9

echo secret > hidden1
echo notsecret > nonhidden2

! "$TRY" -n -E hidden1 cat hidden1 | grep secret
28 changes: 27 additions & 1 deletion try
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ try() {
findmnt --real -r -o target -n >>"$DIRS_AND_MOUNTS"
sort -u -o "$DIRS_AND_MOUNTS" "$DIRS_AND_MOUNTS"

# Setup excluded entries
excldir="$SANDBOX_DIR/excldir"
if [ -n "$EXCL_ENTS" ]
then
OLDIFS=$IFS
IFS=":"
mkdir "$excldir"
for exclent in $EXCL_ENTS
do
whiteout_file="$SANDBOX_DIR/excldir/$(realpath "$exclent")"
mkdir -p "$(dirname "$whiteout_file")"
mknod "$whiteout_file" c 0 0
done
IFS=$OLDIFS
fi

# Calculate UPDATED_DIRS_AND_MOUNTS that contains the merge arguments in LOWER_DIRS
UPDATED_DIRS_AND_MOUNTS="$SANDBOX_DIR"/mounts.updated
export UPDATED_DIRS_AND_MOUNTS
Expand All @@ -90,6 +106,11 @@ try() {
OLDIFS=$IFS
IFS=":"

if [ -d "$excldir/$mountpoint" ]
then
new_mountpoint="$excldir/$mountpoint"
fi

for lower_dir in $LOWER_DIRS
do
temp_mountpoint="$lower_dir/upperdir$mountpoint"
Expand Down Expand Up @@ -627,7 +648,7 @@ NO_COMMIT="interactive"
# We move it to $SANDBOX_DIR/ignore in `try()`, but delete it when we don't move it.
IGNORE_FILE="$(mktemp --suffix ".try-$EXECID")"

while getopts ":yvnhxi:D:U:L:" opt
while getopts ":yvnhxi:D:U:L:E:" opt
do
case "$opt" in
(y) NO_COMMIT="commit";;
Expand All @@ -645,6 +666,11 @@ do
fi
LOWER_DIRS="$OPTARG"
NO_COMMIT="quiet";;
(E) if [ -n "$EXCL_ENTS" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not allow this to work like -i, where you can specify multiple ignores on the command-line?

then
error "the -E option has been specified multiple times" 2
fi
EXCL_ENTS="$OPTARG";;
(v) echo "$TRY_COMMAND version $TRY_VERSION" >&2
exit 0;;
(U) if ! [ -x "$OPTARG" ]
Expand Down
Loading