Skip to content

Add an option to keep symlinks when unpacking #63

Closed

Description

@hasufell

Haskell tar currently emulates symlinks by copying:

emulateLinks = mapM_ $ \(relPath, relLinkTarget) ->
let absPath = baseDir </> relPath
absTarget = FilePath.Native.takeDirectory absPath </> relLinkTarget
in copyFile absTarget absPath

This is probably the most cross-platform way, but on platforms where symlinks are known to work, there should be a version of unpack that just creates the correct symlinks.

Note that tar currently also cannot extract archives with broken symlinks (because it cannot copy something that doesn't exist). This new version unpack' :: Exception e => Bool -> FilePath -> Entries e -> IO () would not suffer from this problem either.

New windows versions seems to support symlinks: https://hackage.haskell.org/package/directory-1.3.6.1/docs/System-Directory.html#g:6


The implementation isn't hard, but this needs to be decided first as part of the public API.

Activity

  1. Bodigrim commented on Apr 2, 2021

    @Bodigrim
    Contributor

    I tend to avoid providing an API with both foo and foo', which are almost identical, but not quite the same. This will be a constant source of users' confusion.

    Is there a reason to stick to a current behaviour of unpack (except for compatibility with ancient directory)? Could we create symlinks by default?

  2. hasufell commented on Apr 2, 2021

    @hasufell
    MemberAuthor

    Could we create symlinks by default?

    Well, I don't know if all windows versions have this. The directory documentation reads like not all do and that it's filesystem dependent (even worse) and may require administrator privileges. So I don't think this is generally safe.

    I tend to avoid providing an API with both foo and foo', which are almost identical, but not quite the same. This will be a constant source of users' confusion.

    I disagree, because I prefer to not break existing API, especially when adding experimental features. The naming can be improved.

  3. hasufell commented on Apr 2, 2021

    @hasufell
    MemberAuthor

    The only question mark here is really windows, I see the following solutions:

    1. provide a separate unpack': breaks no API, can be marked experimental
    2. add a configuration parameter to existing unpack to toggle symlink behavior: will break existing API, but avoid a separate function... I'm not a fan
    3. make symlink recreation default for unix and for windows:
      • make it default as well and fail hard if the system doesn't support symlinks (pretty rough)
      • make it default, but fall back to file copying (safe, but may be quite surprising)
      • always use file copying on windows (diverging behavior between platforms)

    We can maybe have a look how other cross-platform tar implementations handle this?

  4. added a commit that references this issue on Apr 4, 2021
    8e56a35
  5. hasufell commented on Apr 4, 2021

    @hasufell
    MemberAuthor

    Implemented in my existing PR:

  6. added 3 commits that reference this issue on Apr 4, 2021
    4b01196
    01757ff
    f05c544
  7. added 8 commits that reference this issue on Nov 15, 2023
    f98aec2
    f536ab1
    1c1c806
    15d32eb
    da37bed
    41f2ba0
    eb73383
    596631d
  8. added a commit that references this issue on Jul 17, 2024
    c7b792a
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