-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Description
@carlossanlop @jozkee do we need these checks:
runtime/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs
Lines 504 to 523 in ea4f2cc
| if (!string.IsNullOrEmpty(linkTargetPath)) | |
| { | |
| string? targetDirectoryPath = Path.GetDirectoryName(linkTargetPath); | |
| // If the destination target contains a directory segment, need to check that it exists | |
| if (!string.IsNullOrEmpty(targetDirectoryPath) && !Path.Exists(targetDirectoryPath)) | |
| { | |
| throw new IOException(SR.Format(SR.TarSymbolicLinkTargetNotExists, filePath, linkTargetPath)); | |
| } | |
| if (EntryType is TarEntryType.HardLink) | |
| { | |
| if (!Path.Exists(linkTargetPath)) | |
| { | |
| throw new IOException(SR.Format(SR.TarHardLinkTargetNotExists, filePath, linkTargetPath)); | |
| } | |
| else if (Directory.Exists(linkTargetPath)) | |
| { | |
| throw new IOException(SR.Format(SR.TarHardLinkToDirectoryNotAllowed, filePath, linkTargetPath)); | |
| } | |
| } |
I'm not sure what the Path.Exists is about?
For the hard link, it seems they check conditions on which creating the hard link will fail. So we might just as well fail when the link gets created.
If we can get rid of the checks, we can simplify the code a little because there is no need to pass around linkTargetPath to this method.
I tried leaving them out, and there were no test failures.