1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 03:33:22 +08:00

Rename and xmldoc hard link creation method

This commit is contained in:
Bartłomiej Dach 2022-12-28 21:23:06 +01:00
parent cadd487c75
commit 04d4b4a6ce
No known key found for this signature in database
2 changed files with 13 additions and 5 deletions

View File

@ -65,7 +65,7 @@ namespace osu.Game.Database
if (data is FileStream fs && preferHardLinks) if (data is FileStream fs && preferHardLinks)
{ {
// attempt to do a fast hard link rather than copy. // attempt to do a fast hard link rather than copy.
if (HardLinkHelper.AttemptHardLink(Storage.GetFullPath(file.GetStoragePath(), true), fs.Name)) if (HardLinkHelper.TryCreateHardLink(Storage.GetFullPath(file.GetStoragePath(), true), fs.Name))
return; return;
} }

View File

@ -30,7 +30,7 @@ namespace osu.Game.IO
File.WriteAllText(testSourcePath, string.Empty); File.WriteAllText(testSourcePath, string.Empty);
// Test availability by creating an arbitrary hard link between the source and destination paths. // Test availability by creating an arbitrary hard link between the source and destination paths.
return AttemptHardLink(testDestinationPath, testSourcePath); return TryCreateHardLink(testDestinationPath, testSourcePath);
} }
catch catch
{ {
@ -54,15 +54,23 @@ namespace osu.Game.IO
} }
} }
public static bool AttemptHardLink(string testDestinationPath, string testSourcePath) /// <summary>
/// Attempts to create a hard link from <paramref name="sourcePath"/> to <paramref name="destinationPath"/>,
/// using platform-specific native methods.
/// </summary>
/// <remarks>
/// Hard links are only available on Windows and Linux.
/// </remarks>
/// <returns>Whether the hard link was successfully created.</returns>
public static bool TryCreateHardLink(string destinationPath, string sourcePath)
{ {
switch (RuntimeInfo.OS) switch (RuntimeInfo.OS)
{ {
case RuntimeInfo.Platform.Windows: case RuntimeInfo.Platform.Windows:
return CreateHardLink(testDestinationPath, testSourcePath, IntPtr.Zero); return CreateHardLink(destinationPath, sourcePath, IntPtr.Zero);
case RuntimeInfo.Platform.Linux: case RuntimeInfo.Platform.Linux:
return link(testSourcePath, testDestinationPath) == 0; return link(sourcePath, destinationPath) == 0;
default: default:
return false; return false;