TarWriter should normalize symlink destination paths
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Currently, TAR archives with symlinks created on Windows don't work correclty on Linux and vice versa, because of directory separator differences:
On Windows:
```csharp
File.WriteAllText("output/file", "Hello, World!");
File.CreateSymbolicLink("output/link", ".\\file");
TarFile.CreateFromDirectory("output", "output.tar", true);
```
Will create a working simlink from `link` to `file`, but examining the tar archive contents shows:
Note the `\` in the `linkpath` property. Attempts to extract this on Linux yield:
```
rzikm@radekzikmund-desktop:/mnt/d/DotnetSandbox$ tar xf output.tar -C /tmp/extracted/
rzikm@radekzikmund-desktop:/tmp/extracted/output$ ls -la
total 12
drwxr-xr-x 2 rzikm rzikm 4096 Apr 13 10:25 .
drwxr-xr-x 3 rzikm rzikm 4096 Apr 13 10:27 ..
-rwxr-xr-x 1 rzikm rzikm 7 Apr 13 10:24 file
lrwxrwxrwx 1 rzikm rzikm 6 Apr 13 10:25 link -> '.\file'
rzikm@radekzikmund-desktop:/tmp/extracted/output$ cat link
cat: link: No such file or directory
```
I think we can safely introduce path normalization on Windows so that we always store `linkpath`s as POSIX paths, and convert them to Windows paths during extraction, that shouldn't break any currently working scenario and should close some cross-compat gaps around symlinks in TAR.
Contributor guide
Assessment
This issue has not been assessed yet.