Skip to content

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

Closed

Description

@sensslen

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

Activity

  1. asleire commented on May 21, 2021

    @asleire

    Any known workarounds?

  2. sensslen commented on May 21, 2021

    @sensslen
    ContributorAuthor

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

  3. changed the title [-]Linux: Tar archive is generated from root path[/-] [+]Linux: Tar archive file root path is not stripped from file paths[/+] on May 21, 2021
  4. piksel commented on May 21, 2021

    @piksel
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions