Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Wrong directory structure because directories are added recursively #116

Closed
sithembiso opened this issue Nov 19, 2018 · 3 comments
Closed

Comments

@sithembiso
Copy link

I've implemented a way to support exclusions (which is outside the scope of this library), but it only works if I have complete control over the sources I provide. Here is an example below:

targz := &archiver.TarGz{
    Tar: &archiver.Tar{
        OverwriteExisting: true,
        MkdirAll:          true,
    },
}

sources := []string{"tmp/client-dir/README", "tmp/client-dir/src/index.html"}
if err := targz.Archive(sources, opts.Target); err != nil {
    return stacktrace.Propagate(err, "Could not archive the contents of: "+opts.Src)
}

I'm expecting the structure to look like this:

tmp/client-dir/
├── README
└── src
    └── index.html

Instead, I am getting:

tmp/client-dir/
├── README
└── index.html

Note: I've already tried add the directory to the sources like this []string{"tmp/client-dir/README", "tmp/client-dir/src", "tmp/client-dir/src/index.html"} but because it's adding files recursively, I end up with duplicated files (I still get files from the nested directory on the root).

Also, this wouldn't work for my use case because I want to have filtered the files before creating the archive. Directories being added recursively defeats this purpose.

Related to #16, but not a feature request.

@mholt
Copy link
Owner

mholt commented Nov 19, 2018

So... what is it you want exactly? You want directories to not be added recursively?

@sithembiso
Copy link
Author

I think that is one of two things. What I would like to ascertain first is:
If my sources look like this sources := []string{"foo/bar/index.html"} should I not end up with this in my archive?

foo
└── bar
    └── index.html

If that's true then we need to make sure that the directories in the path (foo and bar) get reproduced on in the archive somehow.

@mholt
Copy link
Owner

mholt commented Nov 20, 2018

No, this is working as documented:

    // Archive adds all the files or folders in sources
    // to an archive to be created at destination. Files
    // are added to the root of the archive, and directories
    // are walked and recursively added, preserving folder
    // structure.
    Archive(sources []string, destination string) error

If you want to preserve folder structure, specify the top-level folder you want to include.

@mholt mholt closed this as completed Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants