Skip to content

Commit 3991397

Browse files
committed
feat: create dir at -r/-w path if it does not exist
1 parent 402d0ca commit 3991397

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ pkgs.nixosTest {
421421
wrap -p bash -c 'test -d "$HOME" -a -w "$HOME" && echo ok' | grep '^ok$' ||
422422
(echo 'Unexpected: $HOME not created or not writable inside sandbox'; false)
423423
"""))
424+
425+
with subtest("r/w shared directory is created if it does not exist"):
426+
machine.succeed(as_alice("""
427+
export SOME_DIR=/tmp/some-dir
428+
rm -rf "$SOME_DIR"
429+
430+
wrap -p -e SOME_DIR -r "$SOME_DIR" bash -c 'test -d "$SOME_DIR" && echo ok' | grep '^ok$' ||
431+
(echo 'Unexpected: -r $SOME_DIR does not create directory'; false)
432+
wrap -p -e SOME_DIR -w "$SOME_DIR" bash -c 'test -d "$SOME_DIR" && echo ok' | grep '^ok$' ||
433+
(echo 'Unexpected: -w $SOME_DIR does not create directory'; false)
434+
"""))
424435
'';
425436
}
426437

wrap.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,17 @@ while getopts "r:w:e:abcdfhmnpuv" opt; do
179179

180180
# bind / mount a path readonly in sandbox to the same path as host
181181
r)
182+
# Create a directory if the path does not exist
183+
mkdir -p "$OPTARG" || true
184+
182185
bwrap_opts+=(--ro-bind "$OPTARG" "$OPTARG")
183186
;;
184187

185188
# bind / mount a path read/write in sandbox to the same path as host
186189
w)
190+
# Create a directory if the path does not exist
191+
mkdir -p "$OPTARG" || true
192+
187193
bwrap_opts+=(--bind "$OPTARG" "$OPTARG")
188194
;;
189195

@@ -307,6 +313,7 @@ while getopts "r:w:e:abcdfhmnpuv" opt; do
307313
usage
308314
exit 1
309315
;;
316+
310317
:)
311318
usage
312319
exit 1

0 commit comments

Comments
 (0)