mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 17:12:54 +08:00
Move duplicated code into its own method
This commit is contained in:
parent
f32564652b
commit
53bca947d1
@ -64,19 +64,8 @@ namespace osu.Game.Database
|
|||||||
private void copyToStore(RealmFile file, Stream data, bool preferHardLinks)
|
private void copyToStore(RealmFile file, Stream data, bool preferHardLinks)
|
||||||
{
|
{
|
||||||
// attempt to do a fast hard link rather than copy.
|
// attempt to do a fast hard link rather than copy.
|
||||||
if (data is FileStream fs && preferHardLinks)
|
if (data is FileStream fs && preferHardLinks && HardLinkHelper.AttemptHardLink(Storage.GetFullPath(file.GetStoragePath(), true), fs.Name))
|
||||||
{
|
return;
|
||||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
|
||||||
{
|
|
||||||
if (HardLinkHelper.CreateHardLink(Storage.GetFullPath(file.GetStoragePath(), true), fs.Name, IntPtr.Zero))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
|
|
||||||
{
|
|
||||||
if (HardLinkHelper.link(fs.Name, Storage.GetFullPath(file.GetStoragePath(), true)) == 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Seek(0, SeekOrigin.Begin);
|
data.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
@ -28,16 +28,9 @@ namespace osu.Game.IO
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
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);
|
||||||
bool isHardLinkAvailable = false;
|
|
||||||
|
|
||||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
|
||||||
isHardLinkAvailable = CreateHardLink(testDestinationPath, testSourcePath, IntPtr.Zero);
|
|
||||||
else if (RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
|
|
||||||
isHardLinkAvailable = link(testSourcePath, testDestinationPath) == 0;
|
|
||||||
|
|
||||||
return isHardLinkAvailable;
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -61,6 +54,18 @@ namespace osu.Game.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool AttemptHardLink(string testDestinationPath, string testSourcePath)
|
||||||
|
{
|
||||||
|
bool isHardLinkAvailable = false;
|
||||||
|
|
||||||
|
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||||
|
isHardLinkAvailable = CreateHardLink(testDestinationPath, testSourcePath, IntPtr.Zero);
|
||||||
|
else if (RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
|
||||||
|
isHardLinkAvailable = link(testSourcePath, testDestinationPath) == 0;
|
||||||
|
|
||||||
|
return isHardLinkAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
// For future use (to detect if a file is a hard link with other references existing on disk).
|
// For future use (to detect if a file is a hard link with other references existing on disk).
|
||||||
public static int GetFileLinkCount(string filePath)
|
public static int GetFileLinkCount(string filePath)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user