Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default implementation with warning for symbolic links #513

Merged

Conversation

RealOrko
Copy link

@RealOrko RealOrko commented May 21, 2020

Hi

I changed the default implementation for writing symbolic links to emit a warning instead of throwing an exception for this issue.

Not sure how this runs for performance.

Another thing we could try is to create platform specific commands that call out to a shell command for the various platforms.

Something like:

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
   ShellCommands.Exec($"mklink /H {source} {target}")
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
   ShellCommands.Exec($"ln -s {target} {source}")
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
   ShellCommands.Exec($"ln -s {target} {source}")
}

…original GitHub issue for the DOTNET runtime
@RealOrko
Copy link
Author

RealOrko commented May 21, 2020

After using this source code for launching OS specific shell commands, I did manage to unpack a tar with symbolic links using this code:

var opt = new ExtractionOptions {
    ExtractFullPath = true,
    Overwrite = true,
    WriteSymbolicLink = 
        (symbolicLink, actualPath) =>
        {
            if (Process.OperatingSystem.IsLinux() || Process.OperatingSystem.IsMacOS())
            {
                var symbolicLinkDirectory = Path.GetDirectoryName(symbolicLink);
                if (!Directory.Exists(symbolicLinkDirectory))
                {
                    Directory.CreateDirectory(symbolicLinkDirectory);
                }

                var result = new Process.Process()
                    .SetWorkingDirectory(symbolicLinkDirectory)
                    .SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH"))
                    .Execute("ln", "-s", actualPath, symbolicLink);

                if (result.HasErrorOutput())
                {
                    Console.WriteLine(result.ErrorOutput);
                }
            }
            else
            {
                Console.WriteLine($"Could not write symlink {symbolicLink} -> {actualPath}, for more information please see https://github.com/dotnet/runtime/issues/24271");
            }

        }
};

@adamhathcock
Copy link
Owner

Thanks for this. Should probably put some kind of warning in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants