Skip to content

TarEntry: link target path checks #78695

@tmds

Description

@tmds

@carlossanlop @jozkee do we need these checks:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions