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

Tar: file changed as we read it #116

Open
4ilo opened this issue Apr 15, 2021 · 1 comment
Open

Tar: file changed as we read it #116

4ilo opened this issue Apr 15, 2021 · 1 comment

Comments

@4ilo
Copy link

4ilo commented Apr 15, 2021

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

@thekyz
Copy link

thekyz commented Apr 22, 2021

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) .
    """.
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants