SharpZipLib
SharpZipLib copied to clipboard
Linux: Tar archive file root path is not stripped from file paths
Steps to reproduce
- Create a new Tar Archive stream
- Set the RootPath to the path to the Path to be added
- 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
Any known workarounds?
Well there is #582 which fixes this issue in most scenarios…
@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);