Use switch statement in `AttemptHardLink()`

This commit is contained in:
Bartłomiej Dach 2022-12-28 21:20:49 +01:00
parent 2c346eae0d
commit cadd487c75
No known key found for this signature in database
1 changed files with 9 additions and 6 deletions

View File

@ -56,14 +56,17 @@ void cleanupFiles()
public static bool AttemptHardLink(string testDestinationPath, string testSourcePath)
{
bool isHardLinkAvailable = false;
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.Windows:
return CreateHardLink(testDestinationPath, testSourcePath, IntPtr.Zero);
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
isHardLinkAvailable = CreateHardLink(testDestinationPath, testSourcePath, IntPtr.Zero);
else if (RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
isHardLinkAvailable = link(testSourcePath, testDestinationPath) == 0;
case RuntimeInfo.Platform.Linux:
return link(testSourcePath, testDestinationPath) == 0;
return isHardLinkAvailable;
default:
return false;
}
}
// For future use (to detect if a file is a hard link with other references existing on disk).