Fix System.IO.IOException: 'Unable to remove the file to be replaced. ' #10

Based on: 00416bc92f
This commit is contained in:
Rinat Abzalov 2021-12-13 12:15:37 +05:00 committed by Wizou
parent 15c3fda05d
commit 62dad83370
2 changed files with 8 additions and 9 deletions

2
.github/dev.yml vendored
View file

@ -2,7 +2,7 @@ pr: none
trigger:
- master
name: 1.7.6-dev.$(Rev:r)
name: 1.7.7-dev.$(Rev:r)
pool:
vmImage: ubuntu-latest

View file

@ -87,14 +87,13 @@ namespace WTelegram
encryptor.TransformBlock(utf8Json, 0, utf8Json.Length & ~15, output, 48);
utf8Json.AsSpan(utf8Json.Length & ~15).CopyTo(finalBlock);
encryptor.TransformFinalBlock(finalBlock, 0, utf8Json.Length & 15).CopyTo(output.AsMemory(48 + utf8Json.Length & ~15));
if (!File.Exists(_pathname))
File.WriteAllBytes(_pathname, output);
else lock (this)
{
string tempPathname = _pathname + ".tmp";
File.WriteAllBytes(tempPathname, output);
File.Replace(tempPathname, _pathname, null);
}
string tempPathname = _pathname + ".tmp";
lock (this)
{
File.WriteAllBytes(tempPathname, output);
File.Delete(_pathname);
File.Move(tempPathname, _pathname);
}
}
}
}