Git Product home page Git Product logo

Comments (4)

alexeagle avatar alexeagle commented on June 11, 2024

Thanks, can you isolate this a bit more? Is that genrule that does the manipulation at fault, or can you reproduce a bug without it?

I think it's probably intentional that the order of mtree lines affects the tar. mtree has support for state, like you can effectively "cd somedir" and then subsequent lines are affected.

from bazel-lib.

bmyers-ozette avatar bmyers-ozette commented on June 11, 2024

Thanks for the reply and for taking a look! The issue seems to only reproduce for files the are in the root directory of the tar according to the mtree spec.

Here's a repro case without the genrule to illustrate. Resulting tar has nginx-template-based.conf under conf.d instead of at the root:

tar(
    name = "foo",
    srcs = [":foo_files"],
    mtree = [
        "conf.d uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "conf.d/http.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/conf.d/http.conf",
        "nginx-template-based.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/nginx-template-based.conf",
    ],
)
$ tar -tvf foo.tar
drwxr-xr-x 0/0               0 2023-01-01 02:00 conf.d/
-rwxr-xr-x 0/0            1426 2023-01-01 02:00 conf.d/http.conf
-rwxr-xr-x 0/0             636 2023-01-01 02:00 conf.d/nginx-template-based.conf

Reordered mtree has nginx-template-based.conf in the root as expected:

tar(
    name = "bar",
    srcs = [":foo_files"],
    mtree = [
        "nginx-template-based.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/nginx-template-based.conf",
        "conf.d uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "conf.d/http.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/conf.d/http.conf",
    ],
)
$ tar -tvf bar.tar
-rwxr-xr-x 0/0             636 2023-01-01 02:00 nginx-template-based.conf
drwxr-xr-x 0/0               0 2023-01-01 02:00 conf.d/
-rwxr-xr-x 0/0            1426 2023-01-01 02:00 conf.d/http.conf

If the files are nested under a prefix, it also seems to work as I would expect:

tar(
    name = "foobar",
    srcs = [":foo_files"],
    mtree = [
        "app uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "app/nginx uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "app/nginx/conf uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "app/nginx/conf/conf.d uid=0 gid=0 time=1672560000 mode=0755 type=dir",
        "app/nginx/conf/conf.d/http.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/conf.d/http.conf",
        "app/nginx/conf/nginx-template-based.conf uid=0 gid=0 time=1672560000 mode=0755 type=file content=app/nginx/conf/nginx-template-based.conf",
    ],
)
$ tar -tvf foobar.tar
drwxr-xr-x 0/0               0 2023-01-01 02:00 app/
drwxr-xr-x 0/0               0 2023-01-01 02:00 app/nginx/
drwxr-xr-x 0/0               0 2023-01-01 02:00 app/nginx/conf/
drwxr-xr-x 0/0               0 2023-01-01 02:00 app/nginx/conf/conf.d/
-rwxr-xr-x 0/0            1426 2023-01-01 02:00 app/nginx/conf/conf.d/http.conf
-rwxr-xr-x 0/0             636 2023-01-01 02:00 app/nginx/conf/nginx-template-based.conf

Hope that helps clarify the issue. If it's intentional that the order of mtree lines affects the tar, seems like creating an mtree_spec from a globbed filegroup will give different behavior just depending on the alphabetical ordering of the directories and files contained.

from bazel-lib.

thesayyn avatar thesayyn commented on June 11, 2024

this is how mtrees work, you either have to add ./ to the dir entry, or have / as the suffix for the dir entry.
This is working as expected.

from bazel-lib.

bmyers-ozette avatar bmyers-ozette commented on June 11, 2024

Thanks @thesayyn,

Seems like this is a nuance to the mtrees that is easy to trip over if you naively try to strip off a prefix from the mtree_spec output. I believe the genrule in the tests that is referenced from the tar documentation would be susceptible to this issue: https://github.com/aspect-build/bazel-lib/blob/main/lib/tests/tar/BUILD.bazel#L128-L145

Anyway, adding the / suffix did the trick so I think this can be closed. Thanks again for the reply and explanation.

from bazel-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.