From 5ef55d21805679f46407008bda0e52a210497bee Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 31 Aug 2019 21:35:01 +0200 Subject: [PATCH] Fixed DownloadFile when file already exists --- src/NzbDrone.Common.Test/Http/HttpClientFixture.cs | 4 ++-- src/NzbDrone.Common/Http/HttpClient.cs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs index 80741132a..668957cf5 100644 --- a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs @@ -300,12 +300,12 @@ namespace NzbDrone.Common.Test.Http { var file = GetTempFilePath(); - Assert.Throws(() => Subject.DownloadFile("https://download.readarr.com/wrongpath", file)); + Assert.Throws(() => Subject.DownloadFile("https://download.readarr.com/wrongpath", file)); File.Exists(file).Should().BeFalse(); File.Exists(file + ".part").Should().BeFalse(); - ExceptionVerification.ExpectedWarns(1); + ExceptionVerification.ExpectedWarns(0); } [Test] diff --git a/src/NzbDrone.Common/Http/HttpClient.cs b/src/NzbDrone.Common/Http/HttpClient.cs index ff4522e35..856643b3e 100644 --- a/src/NzbDrone.Common/Http/HttpClient.cs +++ b/src/NzbDrone.Common/Http/HttpClient.cs @@ -258,6 +258,11 @@ namespace NzbDrone.Common.Http } stopWatch.Stop(); + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + File.Move(fileNamePart, fileName); _logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds); } @@ -266,7 +271,7 @@ namespace NzbDrone.Common.Http if (File.Exists(fileNamePart)) { File.Delete(fileNamePart); - } + } } }