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

add WithBaseDir option to tar context #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshrwolf
Copy link

Adds a WithBaseDir option to the tar context to allow building tarballs with more control over the archives root directory.

This is useful when the unarchive process isn't performed by the consumer, but the consumer still wants to adhere to some required directory structure (such as in kontext, where the archive is used to create a container layer unpacked at /)

This option is disabled by default.

Signed-off-by: Josh Wolf <josh@wolfs.io>
@@ -143,7 +144,7 @@ func (c *Context) writeTar(ctx context.Context, tw *tar.Writer, fsys fs.FS, user
header.Devminor = int64(minor)
}
// work around some weirdness, without this we wind up with just the basename
header.Name = path
header.Name = filepath.Join(c.BaseDir, path)
Copy link
Author

Choose a reason for hiding this comment

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

this should be equivalent to header.Name = path when c.BaseDir is the zero value, but please correct me if I'm wrong!

@joshrwolf joshrwolf requested a review from deitch June 7, 2023 13:46
@deitch
Copy link
Contributor

deitch commented Jun 7, 2023

I don't fully understand what this change tries to do. Let's say I have a directory tree like this:

foo
  bar
    baz
      filea
      fileb
      subdir
         sub1
         sub2

And I want everything under /foo/bar/baz/ to be in my tarball. Then I already have that, and all subpaths, e.g. /foo/bar/baz/filea and /foo/bar/baz/subdir will appear just like that in the repo, fileaa and subdir, etc.

Unless you are saying you want them to appear in the tarball as prefix/filea and prefix/fileb etc? Is this about modifying what appears inside the tarball?

@joshrwolf
Copy link
Author

joshrwolf commented Jun 7, 2023

Unless you are saying you want them to appear in the tarball as prefix/filea and prefix/fileb etc? Is this about modifying what appears inside the tarball?

This. If there's a better way to achieve this within the confines of FullFS, please let me know!

Also, here is a rough draft of the downstream impact this would have for something like kontext

@deitch
Copy link
Contributor

deitch commented Jun 7, 2023

I get it. I don't see any reason not to support it.

I do wonder if this is the best way to achieve it? Thinking about tar commands, usually, if I, as a tar consumer, want my output to be in a certain directory, I would do:

$ mkdir /target/dir
$ tar -C /target/dir -xvf mytarfile.tar

I only create the prefix if I want every potential consumer to have it (which is a valid use case).

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

Successfully merging this pull request may close these issues.

None yet

2 participants