From 63886417904a20140d4718f1115664e3f89c57c1 Mon Sep 17 00:00:00 2001 From: isaac Date: Fri, 10 May 2024 17:18:29 +0930 Subject: [PATCH 1/3] Spiking filesystem changes --- .../AzureAppServiceZipDeployBehaviour.cs | 8 +- .../FunctionAppenderScriptWrapper.cs | 2 +- .../Packages/NuGet/LocalNuGetPackage.cs | 6 +- .../Plumbing/FileSystem/FileAccess.cs | 51 ++++++++++++ .../Plumbing/FileSystem/FileOperations.cs | 78 +++++++++---------- .../Plumbing/FileSystem/TemporaryFile.cs | 4 +- .../Download/GitHubPackageDownloader.cs | 11 +-- .../NuGet/InternalNuGetPackageDownloader.cs | 2 +- .../NuGet/NuGetFileSystemDownloader.cs | 7 +- .../NuGetFilesystemDownloaderFixture.cs | 5 +- 10 files changed, 116 insertions(+), 58 deletions(-) create mode 100644 source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs diff --git a/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs b/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs index 4ec930bca..124c45979 100644 --- a/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs +++ b/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs @@ -19,6 +19,7 @@ using Calamari.Common.Commands; using Calamari.Common.FeatureToggles; using Calamari.Common.Plumbing.Extensions; +using Calamari.Common.Plumbing.FileSystem; using Calamari.Common.Plumbing.Logging; using Calamari.Common.Plumbing.Pipeline; using Calamari.Common.Plumbing.Variables; @@ -33,7 +34,8 @@ internal class AzureAppServiceZipDeployBehaviour : IDeployBehaviour { static readonly TimeSpan PollingTimeout = TimeSpan.FromMinutes(3); static readonly TimeoutPolicy AsyncZipDeployTimeoutPolicy = Policy.TimeoutAsync(PollingTimeout, TimeoutStrategy.Optimistic); - + static readonly ICalamariFileSystem CalamariFileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); + public AzureAppServiceZipDeployBehaviour(ILog log) { Log = log; @@ -360,9 +362,9 @@ static void CleanupUploadFile(string? uploadPath) i => TimeSpan.FromMilliseconds(200)) .Execute(() => { - if (File.Exists(uploadPath)) + if (CalamariFileSystem.FileExists(uploadPath)) { - File.Delete(uploadPath!); + CalamariFileSystem.DeleteFile(uploadPath!); } }); } diff --git a/source/Calamari.Common/Features/FunctionScriptContributions/FunctionAppenderScriptWrapper.cs b/source/Calamari.Common/Features/FunctionScriptContributions/FunctionAppenderScriptWrapper.cs index b692c0f8b..c6eab8ab4 100644 --- a/source/Calamari.Common/Features/FunctionScriptContributions/FunctionAppenderScriptWrapper.cs +++ b/source/Calamari.Common/Features/FunctionScriptContributions/FunctionAppenderScriptWrapper.cs @@ -60,7 +60,7 @@ public CommandResult ExecuteScript(Script script, ScriptSyntax scriptSyntax, ICo destinationFile = Path.Combine(workingDirectory, copyScriptFile); } - File.Copy(scriptFile, destinationFile, true); + fileSystem.CopyFile(scriptFile, destinationFile); } using (var contextScriptFile = new TemporaryFile(scriptFile)) diff --git a/source/Calamari.Common/Features/Packages/NuGet/LocalNuGetPackage.cs b/source/Calamari.Common/Features/Packages/NuGet/LocalNuGetPackage.cs index 52c9f4690..8a74b6a53 100644 --- a/source/Calamari.Common/Features/Packages/NuGet/LocalNuGetPackage.cs +++ b/source/Calamari.Common/Features/Packages/NuGet/LocalNuGetPackage.cs @@ -6,6 +6,7 @@ using System; using System.IO; using Calamari.Common.Plumbing; +using Calamari.Common.Plumbing.FileSystem; using SharpCompress.Archives.Zip; namespace Calamari.Common.Features.Packages.NuGet @@ -14,6 +15,7 @@ public class LocalNuGetPackage { readonly string filePath; readonly Lazy metadata; + static readonly ICalamariFileSystem CalamariFileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); public LocalNuGetPackage(string filePath) { @@ -30,7 +32,7 @@ public LocalNuGetPackage(string filePath) public void GetStream(Action process) { - using (var fileStream = File.OpenRead(filePath)) + using (var fileStream = CalamariFileSystem.OpenFile(filePath, FileAccess.Read)) { process(fileStream); } @@ -38,7 +40,7 @@ public void GetStream(Action process) static ManifestMetadata ReadMetadata(string filePath) { - using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (var fileStream = CalamariFileSystem.OpenFile(filePath, FileMode.Open, FileAccess.Read)) using (var archive = ZipArchive.Open(fileStream)) { foreach (var entry in archive.Entries) diff --git a/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs b/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs new file mode 100644 index 000000000..14453923c --- /dev/null +++ b/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +using Calamari.Common.Plumbing.Logging; +using Polly; + +namespace Calamari.Common.Plumbing.FileSystem +{ + public static class FileAccessChecker + { + public static T IsFileLocked(Func accessFile) + { + try + { + Policy.Handle() + .WaitAndRetry( + 3, + i => TimeSpan.FromMilliseconds(200)) + .Execute(accessFile); + } + catch (Exception e) + { + var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1); + var isLocked = errorCode == 32 || errorCode == 33; + Log.Error($"File is {isLocked}, threw with error code {errorCode}"); + throw e; + } + + return accessFile(); + } + + public static void IsFileLocked(Action accessFile) + { + try + { + Policy.Handle() + .WaitAndRetry( + 3, + i => TimeSpan.FromMilliseconds(200)) + .Execute(accessFile); + } + catch (Exception e) + { + var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1); + var isLocked = errorCode == 32 || errorCode == 33; + Log.Error($"File is {isLocked}, threw with error code {errorCode}"); + throw e; + } + } + } +} \ No newline at end of file diff --git a/source/Calamari.Common/Plumbing/FileSystem/FileOperations.cs b/source/Calamari.Common/Plumbing/FileSystem/FileOperations.cs index 9aa76bd92..992e5d6d8 100644 --- a/source/Calamari.Common/Plumbing/FileSystem/FileOperations.cs +++ b/source/Calamari.Common/Plumbing/FileSystem/FileOperations.cs @@ -40,47 +40,47 @@ public class StandardFile : IFile { public void Delete(string path) { - File.Delete(path); + FileAccessChecker.IsFileLocked(() => File.Delete(path)); } public bool Exists(string? path) { - return File.Exists(path); + return FileAccessChecker.IsFileLocked(() => File.Exists(path)); } public byte[] ReadAllBytes(string path) { - return File.ReadAllBytes(path); + return FileAccessChecker.IsFileLocked(() => File.ReadAllBytes(path)); } public void WriteAllBytes(string path, byte[] bytes) { - File.WriteAllBytes(path, bytes); + FileAccessChecker.IsFileLocked(() => File.WriteAllBytes(path, bytes)); } public void Move(string source, string destination) { - File.Move(source, destination); + FileAccessChecker.IsFileLocked(() => File.Move(source, destination)); } public void SetAttributes(string path, FileAttributes fileAttributes) { - File.SetAttributes(path, fileAttributes); + FileAccessChecker.IsFileLocked(() => File.SetAttributes(path, fileAttributes)); } public DateTime GetCreationTime(string path) { - return File.GetCreationTime(path); + return FileAccessChecker.IsFileLocked(() => File.GetCreationTime(path)); } public Stream Open(string path, FileMode mode, FileAccess access, FileShare share) { - return File.Open(path, mode, access, share); + return FileAccessChecker.IsFileLocked(() => File.Open(path, mode, access, share)); } public void Copy(string source, string destination, bool overwrite) { - File.Copy(source, destination, overwrite); + FileAccessChecker.IsFileLocked(() => File.Copy(source, destination, overwrite)); } } @@ -88,46 +88,46 @@ public class StandardDirectory : IDirectory { public void CreateDirectory(string path) { - Directory.CreateDirectory(path); + FileAccessChecker.IsFileLocked(() => Directory.CreateDirectory(path)); } public void Delete(string path, bool recursive) { - Directory.Delete(path, recursive); + FileAccessChecker.IsFileLocked(() => Directory.Delete(path, recursive)); } public bool Exists(string? path) { - return Directory.Exists(path); + return FileAccessChecker.IsFileLocked(() => Directory.Exists(path)); } public string[] GetFileSystemEntries(string path) { - return Directory.GetFileSystemEntries(path); + return FileAccessChecker.IsFileLocked(() => Directory.GetFileSystemEntries(path)); } public IEnumerable EnumerateDirectories(string path) { - return Directory.EnumerateDirectories(path); + return FileAccessChecker.IsFileLocked(() => Directory.EnumerateDirectories(path)); } public IEnumerable EnumerateDirectoriesRecursively(string path) { - return Directory.EnumerateDirectories(path, "*", SearchOption.AllDirectories); + return FileAccessChecker.IsFileLocked(() => Directory.EnumerateDirectories(path, "*", SearchOption.AllDirectories)); } public virtual IEnumerable EnumerateFiles( string parentDirectoryPath, params string[] searchPatterns) { - return EnumerateFiles(parentDirectoryPath, SearchOption.TopDirectoryOnly, searchPatterns); + return FileAccessChecker.IsFileLocked(() => EnumerateFiles(parentDirectoryPath, SearchOption.TopDirectoryOnly, searchPatterns)); } public virtual IEnumerable EnumerateFilesRecursively( string parentDirectoryPath, params string[] searchPatterns) { - return EnumerateFiles(parentDirectoryPath, SearchOption.AllDirectories, searchPatterns); + return FileAccessChecker.IsFileLocked(() => EnumerateFiles(parentDirectoryPath, SearchOption.AllDirectories, searchPatterns)); } private IEnumerable EnumerateFiles( @@ -136,24 +136,24 @@ private IEnumerable EnumerateFiles( string[] searchPatterns) { return searchPatterns.Length == 0 - ? Directory.EnumerateFiles(parentDirectoryPath, "*", searchOption) + ? FileAccessChecker.IsFileLocked(() => Directory.EnumerateFiles(parentDirectoryPath, "*", searchOption)) : searchPatterns.SelectMany(pattern => - Directory.EnumerateFiles(parentDirectoryPath, pattern, searchOption)).Distinct(); + FileAccessChecker.IsFileLocked(() => Directory.EnumerateFiles(parentDirectoryPath, pattern, searchOption)).Distinct()); } public IEnumerable GetFiles(string path, string searchPattern) { - return Directory.GetFiles(path, searchPattern); + return FileAccessChecker.IsFileLocked(() => Directory.GetFiles(path, searchPattern)); } public IEnumerable GetDirectories(string path) { - return Directory.GetDirectories(path); + return FileAccessChecker.IsFileLocked(() => Directory.GetDirectories(path)); } public string GetCurrentDirectory() { - return Directory.GetCurrentDirectory(); + return FileAccessChecker.IsFileLocked(() => Directory.GetCurrentDirectory()); } } @@ -162,47 +162,47 @@ public class LongPathsFile : IFile { public void Delete(string path) { - Alphaleonis.Win32.Filesystem.File.Delete(path); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.Delete(path)); } public bool Exists(string? path) { - return Alphaleonis.Win32.Filesystem.File.Exists(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.Exists(path)); } public byte[] ReadAllBytes(string path) { - return Alphaleonis.Win32.Filesystem.File.ReadAllBytes(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.ReadAllBytes(path)); } public void WriteAllBytes(string path, byte[] bytes) { - Alphaleonis.Win32.Filesystem.File.WriteAllBytes(path, bytes); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.WriteAllBytes(path, bytes)); } public void Move(string source, string destination) { - Alphaleonis.Win32.Filesystem.File.Move(source, destination); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.Move(source, destination)); } public void SetAttributes(string path, FileAttributes fileAttributes) { - Alphaleonis.Win32.Filesystem.File.SetAttributes(path, fileAttributes); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.SetAttributes(path, fileAttributes)); } public DateTime GetCreationTime(string path) { - return Alphaleonis.Win32.Filesystem.File.GetCreationTime(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.GetCreationTime(path)); } public Stream Open(string path, FileMode mode, FileAccess access, FileShare share) { - return Alphaleonis.Win32.Filesystem.File.Open(path, mode, access, share); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.Open(path, mode, access, share)); } public void Copy(string source, string destination, bool overwrite) { - Alphaleonis.Win32.Filesystem.File.Copy(source, destination, overwrite); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.File.Copy(source, destination, overwrite)); } } @@ -210,42 +210,42 @@ public class LongPathsDirectory : IDirectory { public void CreateDirectory(string path) { - Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(path); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(path)); } public void Delete(string path, bool recursive) { - Alphaleonis.Win32.Filesystem.Directory.Delete(path, recursive); + FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.Delete(path, recursive)); } public bool Exists(string? path) { - return Alphaleonis.Win32.Filesystem.Directory.Exists(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.Exists(path)); } public string[] GetFileSystemEntries(string path) { - return Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntries(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntries(path)); } public IEnumerable EnumerateDirectories(string path) { - return Alphaleonis.Win32.Filesystem.Directory.EnumerateDirectories(path); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.EnumerateDirectories(path)); } public IEnumerable EnumerateDirectoriesRecursively(string path) { - return Alphaleonis.Win32.Filesystem.Directory.EnumerateDirectories(path, "*", SearchOption.AllDirectories); + return FileAccessChecker.IsFileLocked(() => Alphaleonis.Win32.Filesystem.Directory.EnumerateDirectories(path, "*", SearchOption.AllDirectories)); } public IEnumerable EnumerateFiles(string parentDirectoryPath, params string[] searchPatterns) { - return EnumerateFiles(parentDirectoryPath, SearchOption.TopDirectoryOnly, searchPatterns); + return FileAccessChecker.IsFileLocked(() => EnumerateFiles(parentDirectoryPath, SearchOption.TopDirectoryOnly, searchPatterns)); } public IEnumerable EnumerateFilesRecursively(string parentDirectoryPath, params string[] searchPatterns) { - return EnumerateFiles(parentDirectoryPath, SearchOption.AllDirectories, searchPatterns); + return FileAccessChecker.IsFileLocked(() => EnumerateFiles(parentDirectoryPath, SearchOption.AllDirectories, searchPatterns)); } private IEnumerable EnumerateFiles( diff --git a/source/Calamari.Common/Plumbing/FileSystem/TemporaryFile.cs b/source/Calamari.Common/Plumbing/FileSystem/TemporaryFile.cs index 6aae86024..eff78cae0 100644 --- a/source/Calamari.Common/Plumbing/FileSystem/TemporaryFile.cs +++ b/source/Calamari.Common/Plumbing/FileSystem/TemporaryFile.cs @@ -21,7 +21,7 @@ public string Hash { get { - using (var file = File.OpenRead(FilePath)) + using (var file = fileSystem.OpenFile(FilePath, FileAccess.Read)) { var hash = SHA1.Create().ComputeHash(file); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); @@ -33,7 +33,7 @@ public long Size { get { - using (var file = File.OpenRead(FilePath)) + using (var file = fileSystem.OpenFile(FilePath, FileAccess.Read)) { return file.Length; } diff --git a/source/Calamari.Shared/Integration/Packages/Download/GitHubPackageDownloader.cs b/source/Calamari.Shared/Integration/Packages/Download/GitHubPackageDownloader.cs index 0a07e9089..3d45d72e9 100644 --- a/source/Calamari.Shared/Integration/Packages/Download/GitHubPackageDownloader.cs +++ b/source/Calamari.Shared/Integration/Packages/Download/GitHubPackageDownloader.cs @@ -172,8 +172,8 @@ PackagePhysicalFileMetadata DownloadFile(string uri, Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, Extension)); var tempPath = Path.GetTempFileName(); - if (File.Exists(tempPath)) - File.Delete(tempPath); + if (fileSystem.FileExists(tempPath)) + fileSystem.DeleteFile(tempPath); for (var retry = 0; retry < maxDownloadAttempts; ++retry) try @@ -273,13 +273,14 @@ string GetUserAgent() /// Unfortunately the server needs the same logic so that we can ensure that the Hash comparisons match. /// /// - static void DeNestContents(string src, string dest) + void DeNestContents(string src, string dest) { var rootPathSeperator = -1; - using (var readerStram = File.Open(src, FileMode.Open, FileAccess.ReadWrite)) + + using (var readerStram = fileSystem.OpenFile(src, FileMode.Open, FileAccess.ReadWrite)) using (var reader = ReaderFactory.Open(readerStram)) { - using (var writerStream = File.Open(dest, FileMode.CreateNew, FileAccess.ReadWrite)) + using (var writerStream = fileSystem.OpenFile(dest, FileMode.CreateNew, FileAccess.ReadWrite)) using (var writer = WriterFactory.Open(writerStream, ArchiveType.Zip, new ZipWriterOptions(CompressionType.Deflate))) { while (reader.MoveToNextEntry()) diff --git a/source/Calamari.Shared/Integration/Packages/NuGet/InternalNuGetPackageDownloader.cs b/source/Calamari.Shared/Integration/Packages/NuGet/InternalNuGetPackageDownloader.cs index a3c03fb47..e5c4ee940 100644 --- a/source/Calamari.Shared/Integration/Packages/NuGet/InternalNuGetPackageDownloader.cs +++ b/source/Calamari.Shared/Integration/Packages/NuGet/InternalNuGetPackageDownloader.cs @@ -94,7 +94,7 @@ private void DownloadPackageAction(string packageId, IVersion version, Uri feedU // FileSystem feed if (feedUri.IsFile) { - NuGetFileSystemDownloader.DownloadPackage(packageId, version, feedUri, targetFilePath); + NuGetFileSystemDownloader.DownloadPackage(packageId, version, feedUri, targetFilePath, fileSystem); return; } diff --git a/source/Calamari.Shared/Integration/Packages/NuGet/NuGetFileSystemDownloader.cs b/source/Calamari.Shared/Integration/Packages/NuGet/NuGetFileSystemDownloader.cs index 7cc08c3b1..d9f7f6138 100644 --- a/source/Calamari.Shared/Integration/Packages/NuGet/NuGetFileSystemDownloader.cs +++ b/source/Calamari.Shared/Integration/Packages/NuGet/NuGetFileSystemDownloader.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Calamari.Common.Features.Packages.NuGet; +using Calamari.Common.Plumbing.FileSystem; using Calamari.Common.Plumbing.Logging; using Octopus.Versioning; @@ -12,7 +13,7 @@ public class NuGetFileSystemDownloader { private static string NuGetFileExtension = ".nupkg"; - public static void DownloadPackage(string packageId, IVersion version, Uri feedUri, string targetFilePath) + public static void DownloadPackage(string packageId, IVersion version, Uri feedUri, string targetFilePath, ICalamariFileSystem fileSystem) { if (!Directory.Exists(feedUri.LocalPath)) throw new Exception($"Path does not exist: '{feedUri}'"); @@ -33,9 +34,9 @@ select path Log.VerboseFormat("Found package {0} v{1}", packageId, version); Log.Verbose("Downloading to: " + targetFilePath); - using (var targetFile = File.Open(targetFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) + using (var targetFile = fileSystem.OpenFile(targetFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { - using (var fileStream = File.OpenRead(package)) + using (var fileStream = fileSystem.OpenFile(package, FileMode.Open, FileAccess.Read)) { fileStream.CopyTo(targetFile); } diff --git a/source/Calamari.Tests/Fixtures/Integration/Packages/NuGetFilesystemDownloaderFixture.cs b/source/Calamari.Tests/Fixtures/Integration/Packages/NuGetFilesystemDownloaderFixture.cs index 5776e6d2a..edbd529ac 100644 --- a/source/Calamari.Tests/Fixtures/Integration/Packages/NuGetFilesystemDownloaderFixture.cs +++ b/source/Calamari.Tests/Fixtures/Integration/Packages/NuGetFilesystemDownloaderFixture.cs @@ -7,6 +7,7 @@ using Calamari.Common.Plumbing.Extensions; using Calamari.Integration.Packages.NuGet; using Calamari.Testing.Helpers; +using Calamari.Tests.Fixtures.Integration.FileSystem; using Calamari.Tests.Fixtures.Util; using Calamari.Tests.Helpers; using Calamari.Util; @@ -43,7 +44,7 @@ public void FindsAndCopiesNugetPackageWithNugetFileFormat() File.Copy(GetFixtureResource("Samples", "Acme.Core.1.0.0.0-bugfix.nupkg"), originalPath); var downloadPath = Path.Combine(rootDir, "DummyFile.nupkg"); - NuGetFileSystemDownloader.DownloadPackage("Acme.Core", new SemanticVersion("1.0.0.0-bugfix"), new Uri(rootDir), downloadPath); + NuGetFileSystemDownloader.DownloadPackage("Acme.Core", new SemanticVersion("1.0.0.0-bugfix"), new Uri(rootDir), downloadPath, new TestCalamariPhysicalFileSystem()); Assert.AreEqual(HashCalculator.Hash(originalPath), HashCalculator.Hash(downloadPath), "Expected source file to have been copied"); } @@ -54,7 +55,7 @@ public void IgnoresZipPackages() var downloadPath = Path.Combine(rootDir, "DummyFile.nupkg"); Assert.Throws(() => - NuGetFileSystemDownloader.DownloadPackage("Acme.Core", new SemanticVersion("1.0.0.0-bugfix"), new Uri(rootDir), downloadPath) + NuGetFileSystemDownloader.DownloadPackage("Acme.Core", new SemanticVersion("1.0.0.0-bugfix"), new Uri(rootDir), downloadPath, new TestCalamariPhysicalFileSystem()) ); FileAssert.DoesNotExist(downloadPath); } From 3b880e7bfddd1c0b185861bafc3fe4cd8eb07177 Mon Sep 17 00:00:00 2001 From: isaac Date: Mon, 13 May 2024 08:46:36 +0930 Subject: [PATCH 2/3] Fix compilation issue --- .../Behaviors/AzureAppServiceZipDeployBehaviour.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs b/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs index 3697969f0..aa2846463 100644 --- a/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs +++ b/source/Calamari.AzureAppService/Behaviors/AzureAppServiceZipDeployBehaviour.cs @@ -20,7 +20,6 @@ using Calamari.Common.FeatureToggles; using Calamari.Common.Plumbing.Extensions; using Calamari.Common.Plumbing.FileSystem; -using Calamari.Common.Plumbing.FileSystem; using Calamari.Common.Plumbing.Logging; using Calamari.Common.Plumbing.Pipeline; using Calamari.Common.Plumbing.Variables; From 1e3c8fbc8b7cd30c42da33fb25baa672542b1615 Mon Sep 17 00:00:00 2001 From: isaac Date: Mon, 13 May 2024 09:57:22 +0930 Subject: [PATCH 3/3] Update --- source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs b/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs index 14453923c..875fa24ce 100644 --- a/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs +++ b/source/Calamari.Common/Plumbing/FileSystem/FileAccess.cs @@ -33,17 +33,14 @@ public static void IsFileLocked(Action accessFile) { try { - Policy.Handle() - .WaitAndRetry( - 3, - i => TimeSpan.FromMilliseconds(200)) - .Execute(accessFile); + accessFile(); } catch (Exception e) { var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1); var isLocked = errorCode == 32 || errorCode == 33; - Log.Error($"File is {isLocked}, threw with error code {errorCode}"); + Log.Warn($"File is {isLocked}, threw with error code {errorCode}"); + Log.Warn(e.Message); throw e; } }