C#: store replace on Windows tries POSIX-semantics rename first (store-windows-cs) (#152)
This commit is contained in:
parent
73e2131d9a
commit
a85c63712b
5 changed files with 466 additions and 46 deletions
|
|
@ -681,14 +681,7 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
stream.Flush(true);
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
ReplaceExistingFile(tempPath, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Move(tempPath, path);
|
||||
}
|
||||
StoreReplace.Replace(tempPath, path);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -768,26 +761,4 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
|
|||
return held;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReplaceExistingFile(string sourcePath, string destinationPath)
|
||||
{
|
||||
for (var attempt = 0; attempt < 3; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Replace(sourcePath, destinationPath, null);
|
||||
return;
|
||||
}
|
||||
catch (IOException) when (attempt < 2)
|
||||
{
|
||||
Thread.Sleep(10 * (attempt + 1));
|
||||
}
|
||||
catch (UnauthorizedAccessException) when (attempt < 2)
|
||||
{
|
||||
Thread.Sleep(10 * (attempt + 1));
|
||||
}
|
||||
}
|
||||
|
||||
File.Replace(sourcePath, destinationPath, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue