Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Tar: Only treat reparse points marked as junctions or symlinks as actual tar symlinks#89102
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
507f169326846a689064c417585a5348435ddd8c8f53e2ad89d17d9ce934e76375f1b8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System.IO; | ||
| using Microsoft.DotNet.XUnitExtensions; | ||
| using Xunit; | ||
| using Xunit.Sdk; | ||
| namespace System.Formats.Tar.Tests; | ||
| public partial class TarWriter_WriteEntry_File_Tests : TarWriter_File_Base | ||
| { | ||
| [Theory] | ||
| [InlineData(TarEntryFormat.V7)] | ||
| [InlineData(TarEntryFormat.Ustar)] | ||
| [InlineData(TarEntryFormat.Pax)] | ||
| [InlineData(TarEntryFormat.Gnu)] | ||
| public void Add_Junction_As_SymbolicLink(TarEntryFormat format) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you run these tests without elevation? I think it's missing a can create symlinks condition. I've added them a few times when tests failed locally. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starting with Windows 10 Insiders build 14972, symlinks can be created without needing to elevate the console as administrator. https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/ If we still have tests running older Windows versions, they should break in the CI. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Junctions are ancient, they don't require elevation AFAIK. They ran without problem in my local machine. The CI should also cry if something goes wrong. This new test does not create symlinks in the disk by the way, it adds an entry to the tar archive as a symlink. The only thing that gets created in disk is the junction. | ||
| { | ||
| using TempDirectory root = new TempDirectory(); | ||
| string targetName = "TargetDirectory"; | ||
| string junctionName = "JunctionDirectory"; | ||
| string targetPath = Path.Join(root.Path, targetName); | ||
| string junctionPath = Path.Join(root.Path, junctionName); | ||
| Directory.CreateDirectory(targetPath); | ||
| Assert.True(MountHelper.CreateJunction(junctionPath, targetPath)); | ||
| DirectoryInfo junctionInfo = new(junctionPath); | ||
| using MemoryStream archive = new MemoryStream(); | ||
| using (TarWriter writer = new TarWriter(archive, format, leaveOpen: true)) | ||
| { | ||
| writer.WriteEntry(fileName: junctionPath, entryName: junctionPath); | ||
| } | ||
| archive.Position = 0; | ||
| using (TarReader reader = new TarReader(archive)) | ||
| { | ||
| TarEntry entry = reader.GetNextEntry(); | ||
| Assert.Equal(format, entry.Format); | ||
| Assert.NotNull(entry); | ||
| Assert.Equal(junctionPath, entry.Name); | ||
| Assert.Equal(targetPath, entry.LinkName); | ||
| Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType); | ||
| Assert.Null(entry.DataStream); | ||
| VerifyPlatformSpecificMetadata(junctionPath, entry); | ||
| Assert.Null(reader.GetNextEntry()); | ||
| } | ||
| } | ||
| [ConditionalTheory] | ||
| [InlineData(TarEntryFormat.V7)] | ||
| [InlineData(TarEntryFormat.Ustar)] | ||
| [InlineData(TarEntryFormat.Pax)] | ||
| [InlineData(TarEntryFormat.Gnu)] | ||
| public void Add_Unsupported_ReparsePoints_Throws(TarEntryFormat format) | ||
| { | ||
| string? appExecLinkPath = MountHelper.GetAppExecLinkPath(); | ||
| if (appExecLinkPath == null) | ||
| { | ||
| throw new SkipTestException("Could not find an appexeclink in this machine."); | ||
| } | ||
| using MemoryStream archive = new MemoryStream(); | ||
| using TarWriter writer = new TarWriter(archive, format); | ||
| Assert.Throws<IOException>(() => writer.WriteEntry(fileName: appExecLinkPath, "UnsupportedAppExecLink")); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like another data point in favor of having an API for ReparseTags #1908.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.