diff --git a/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSmbArchiveDownloaderTests.cs b/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSmbArchiveDownloaderTests.cs index 04b0b2ba..b91e0b23 100644 --- a/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSmbArchiveDownloaderTests.cs +++ b/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSmbArchiveDownloaderTests.cs @@ -106,7 +106,7 @@ public async Task Download_Returns_Downloaded_Archive_Full_Name() _mockSmbFileStore.Verify(m => m.GetFileInformation(out fileStandardInformation, sharedFileHandle, FileInformationClass.FileStandardInformation), Times.Once); _mockSmbFileStore.Verify(m => m.ReadFile(out data, sharedFileHandle, It.IsAny(), It.IsAny()), Times.Exactly(3)); _mockFileSystemProvider.Verify(m => m.CreateDirectory(TARGET_DIRECTORY), Times.Once); - _mockFileSystemProvider.Verify(m => m.Open(expectedTargetArchiveFullName, FileMode.CreateNew), Times.Once); + _mockFileSystemProvider.Verify(m => m.Open(expectedTargetArchiveFullName, FileMode.Create), Times.Once); _mockFileSystemProvider.Verify(m => m.WriteAsync(It.IsAny(), data, It.IsAny()), Times.Exactly(2)); actualTargetArchiveFullName.Should().Be(expectedTargetArchiveFullName); @@ -187,19 +187,4 @@ await _bbsArchiveDownloader .ThrowExactlyAsync() .WithMessage($"*{NTStatus.STATUS_OBJECT_NAME_NOT_FOUND}*"); } - - [Fact] - public async Task Download_Throws_When_Target_Export_Archive_Already_Exists() - { - // Arrange - var targetArchiveFullName = Path.Join(TARGET_DIRECTORY, _exportArchiveFilename).ToUnixPath(); - _mockFileSystemProvider.Setup(m => m.FileExists(targetArchiveFullName)).Returns(true); - - // Act, Assert - await _bbsArchiveDownloader - .Invoking(x => x.Download(EXPORT_JOB_ID, TARGET_DIRECTORY)) - .Should() - .ThrowExactlyAsync() - .WithMessage($"*{targetArchiveFullName}*"); - } } diff --git a/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSshArchiveDownloaderTests.cs b/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSshArchiveDownloaderTests.cs index fdf664c9..b91ce4b6 100644 --- a/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSshArchiveDownloaderTests.cs +++ b/src/OctoshiftCLI.Tests/bbs2gh/Services/BbsSshArchiveDownloaderTests.cs @@ -56,20 +56,10 @@ public async Task Download_Returns_Downloaded_Archive_Full_Name() null, It.IsAny>())); - _mockFileSystemProvider.Verify(m => m.Open(expectedTargetArchiveFullName, FileMode.CreateNew)); + _mockFileSystemProvider.Verify(m => m.Open(expectedTargetArchiveFullName, FileMode.Create)); actualDownloadedArchiveFullName.Should().Be(expectedTargetArchiveFullName); } - [Fact] - public async Task Download_Throws_When_Target_Export_Archive_Already_Exists() - { - // Arrange - _mockFileSystemProvider.Setup(m => m.FileExists(It.Is(x => x.Contains(_exportArchiveFilename)))).Returns(true); - - // Act, Assert - await _bbsArchiveDownloader.Invoking(x => x.Download(EXPORT_JOB_ID)).Should().ThrowExactlyAsync(); - } - [Fact] public async Task Download_Throws_When_Source_Export_Archive_Does_Not_Exist() { diff --git a/src/bbs2gh/Services/BbsSmbArchiveDownloader.cs b/src/bbs2gh/Services/BbsSmbArchiveDownloader.cs index 10bf26d5..730032c0 100644 --- a/src/bbs2gh/Services/BbsSmbArchiveDownloader.cs +++ b/src/bbs2gh/Services/BbsSmbArchiveDownloader.cs @@ -155,13 +155,8 @@ private string GetLogFriendlySize(long size) private FileStream OpenWriteTargetExportArchive(string targetExportArchiveFullPath) { - if (_fileSystemProvider.FileExists(targetExportArchiveFullPath)) - { - throw new OctoshiftCliException($"Target export archive ({targetExportArchiveFullPath}) already exists."); - } - _fileSystemProvider.CreateDirectory(Path.GetDirectoryName(targetExportArchiveFullPath)); - return _fileSystemProvider.Open(targetExportArchiveFullPath, FileMode.CreateNew); + return _fileSystemProvider.Open(targetExportArchiveFullPath, FileMode.Create); } private void ConnectToHost() diff --git a/src/bbs2gh/Services/BbsSshArchiveDownloader.cs b/src/bbs2gh/Services/BbsSshArchiveDownloader.cs index b6301e25..209ffaef 100644 --- a/src/bbs2gh/Services/BbsSshArchiveDownloader.cs +++ b/src/bbs2gh/Services/BbsSshArchiveDownloader.cs @@ -87,11 +87,6 @@ public async Task Download(long exportJobId, string targetDirectory = IB var targetExportArchiveFullPath = Path.Join(targetDirectory ?? IBbsArchiveDownloader.DEFAULT_TARGET_DIRECTORY, IBbsArchiveDownloader.GetExportArchiveFileName(exportJobId)).ToUnixPath(); - if (_fileSystemProvider.FileExists(targetExportArchiveFullPath)) - { - throw new OctoshiftCliException($"Target export archive ({targetExportArchiveFullPath}) already exists."); - } - if (_sftpClient is BaseClient { IsConnected: false } client) { client.Connect(); @@ -105,7 +100,7 @@ public async Task Download(long exportJobId, string targetDirectory = IB _fileSystemProvider.CreateDirectory(targetDirectory); var sourceExportArchiveSize = _sftpClient.GetAttributes(sourceExportArchiveFullPath)?.Size ?? long.MaxValue; - await using var targetExportArchive = _fileSystemProvider.Open(targetExportArchiveFullPath, FileMode.CreateNew); + await using var targetExportArchive = _fileSystemProvider.Open(targetExportArchiveFullPath, FileMode.Create); await Task.Factory.FromAsync( _sftpClient.BeginDownloadFile( sourceExportArchiveFullPath,