SharpZipLib icon indicating copy to clipboard operation
SharpZipLib copied to clipboard

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

Open sensslen opened this issue 4 years ago • 3 comments

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

sensslen avatar Feb 16 '21 15:02 sensslen

Any known workarounds?

asleire avatar May 21 '21 08:05 asleire

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

sensslen avatar May 21 '21 10:05 sensslen

@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);

piksel avatar May 21 '21 14:05 piksel