From 62dad83370d6922bdaa5349f7248a66edd6657d0 Mon Sep 17 00:00:00 2001 From: Rinat Abzalov Date: Mon, 13 Dec 2021 12:15:37 +0500 Subject: [PATCH] Fix System.IO.IOException: 'Unable to remove the file to be replaced. ' #10 Based on: https://github.com/gitextensions/gitextensions/pull/4252/commits/00416bc92f642c4aff81b6cbcc5a1df38bf4990a --- .github/dev.yml | 2 +- src/Session.cs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/dev.yml b/.github/dev.yml index ac626b6..e355e5d 100644 --- a/.github/dev.yml +++ b/.github/dev.yml @@ -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 diff --git a/src/Session.cs b/src/Session.cs index 9fe35fd..1a675cb 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -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); + } } } } \ No newline at end of file