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

Linux: Tar archive file root path is not stripped from file paths #580

Closed
sensslen opened this issue Feb 16, 2021 · 3 comments
Closed

Linux: Tar archive file root path is not stripped from file paths #580

sensslen opened this issue Feb 16, 2021 · 3 comments

Comments

@sensslen
Copy link
Contributor

sensslen commented Feb 16, 2021

Steps to reproduce

  1. Create a new Tar Archive stream
  2. Set the RootPath to the path to the Path to be added
  3. Add the folder to be added
    var destinationFile = Path.Combine(Path.GetTempPath(), "output.tar");
    using var outStream = File.OpenWrite(destinationFile);
    using var tarArchive = TarArchive.CreateOutputTarArchive(outStream);

    var srcPath= "/tmp/subpath1";
    tarArchive.RootPath = srcPath;

    var tarEntry = TarEntry.CreateEntryFromFile(srcPath);
    tarArchive.WriteEntry(tarEntry, recurse: true);

Note this happens on Linux and not on Windows

Expected behavior

$ tar -tf /tmp/output.tar
subpath2/file1
subpath2/subpath3/file2

Actual behavior

$ tar -tf /tmp/output.tar
tmp/subpath1/subpath2/file1
tmp/subpath1/subpath2/subpath3/file2

Version of SharpZipLib

1.3.1

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
@asleire
Copy link

asleire commented May 21, 2021

Any known workarounds?

@sensslen
Copy link
Contributor Author

Well there is #582 which fixes this issue in most scenarios…

@piksel piksel changed the title Linux: Tar archive is generated from root path Linux: Tar archive file root path is not stripped from file paths May 21, 2021
@piksel
Copy link
Member

piksel commented May 21, 2021

@asleire The easiest workaround right now is to remove the initial slash from the TarArchive.RootPath (not the CreateEntryFromFile argument):

    var destinationFile = Path.Combine(Path.GetTempPath(), "output.tar");
    using var outStream = File.OpenWrite(destinationFile);
    using var tarArchive = TarArchive.CreateOutputTarArchive(outStream);

    var srcPath= "/tmp/subpath1";
    tarArchive.RootPath = srcPath.TrimStart('/');

    var tarEntry = TarEntry.CreateEntryFromFile(srcPath);
    tarArchive.WriteEntry(tarEntry, recurse: true);

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 a pull request may close this issue.

3 participants