sandboxfs
sandboxfs copied to clipboard
Tar: file changed as we read it
Issue
When using tar to create/modify an archive inside a sandboxfs filesystem, sometimes tar will fail with the file changed as we read it error message.
When using sandboxfs this issue is observed regularly but not consistent. Without sandboxfs we never see the issue.
Minimal example
./BUILD
genrule(
name = "test",
tools = ["script.sh"],
outs = ["test.tar"],
cmd = "$(location script.sh) $@",
)
./script.sh
#!/bin/sh -e
for x in {0..1000}; do
mkdir -p workdir
touch workdir/$x.txt
done
tar -C workdir -cf $1 .
for x in {0..100}; do
rm -rf workdir/*
tar -C workdir -xf $1 .
tar -C workdir -cf $1 .
done
Command: bazel clean && bazel build :test --experimental_use_sandboxfs --genrule_strategy=sandboxed --spawn_strategy=sandboxed
You can fix that by having your first genrule output a folder then depend on it with a second genrule and tar that. Something like this (untested):
./BUILD
genrule(
name = "test",
tools = ["script.sh"],
outs = ["test.out"],
cmd = """
mkdir -p $(location test.out)
for x in {0..1000}; do
touch $(location test.out)/$x.txt
done
""".
)
genrule(
name = "tar",
tools = ["script.sh"],
srcs = [":test.out"],
outs = ["test.tar"],
cmd = """
tar cf $(location test.tar) -C $(location test.out) .
""".
)