From b0840f6ad872f7085fd8d62285dc889763a65968 Mon Sep 17 00:00:00 2001 From: Ron Martin Date: Thu, 22 Apr 2021 18:46:03 -0400 Subject: Detect Inability to write to output file Fixes wixtoolset/issues#6425 --- src/WixToolset.Converters/WixConverter.cs | 20 ++++++++++-------- .../ConverterIntegrationFixture.cs | 24 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 80784807..6080eeb9 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -1848,8 +1848,8 @@ namespace WixToolset.Converters { // Ignore the error if explicitly ignored or outside the range of the current operation. if (this.IgnoreErrors.Contains(converterTestType) || - (this.Operation == ConvertOperation.Convert && converterTestType < ConverterTestType.DeclarationPresent) || - (this.Operation == ConvertOperation.Format && converterTestType > ConverterTestType.DeclarationPresent)) + (this.Operation == ConvertOperation.Convert && converterTestType < ConverterTestType.EndIgnoreInConvert) || + (this.Operation == ConvertOperation.Format && converterTestType > ConverterTestType.BeginIgnoreInFormat)) { return false; } @@ -2032,11 +2032,6 @@ namespace WixToolset.Converters /// XmlException, - /// - /// Displayed when a file cannot be accessed; typically when trying to save back a fixed file. - /// - UnauthorizedAccessException, - /// /// Displayed when the whitespace preceding a node is wrong. /// @@ -2047,14 +2042,21 @@ namespace WixToolset.Converters /// WhitespacePrecedingEndElementWrong, - // Before this point, ignore errors on convert operation + /// Before this point, ignore errors on convert operation + EndIgnoreInConvert, /// /// Displayed when the XML declaration is present in the source file. /// DeclarationPresent, - // After this point, ignore errors on format operation + /// + /// Displayed when a file cannot be accessed; typically when trying to save back a fixed file. + /// + UnauthorizedAccessException, + + /// After this point, ignore errors on format operation + BeginIgnoreInFormat, /// /// Displayed when the xmlns attribute is missing from the document element. diff --git a/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs b/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs index cabc89ee..acd7991e 100644 --- a/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs @@ -8,6 +8,7 @@ namespace WixToolsetTest.Converters using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolset.Core; + using WixToolset.Core.ExtensibilityServices; using WixToolset.Core.TestPackage; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -68,6 +69,29 @@ namespace WixToolsetTest.Converters } } + [Fact] + public void CanDetectReadOnlyOutputFile() + { + const string beforeFileName = "SingleFile.wxs"; + var folder = TestData.Get(@"TestData\SingleFile"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(true); + var targetFile = Path.Combine(baseFolder, beforeFileName); + File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName)); + + var info = new FileInfo(targetFile); + info.IsReadOnly = true; + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 4); + var errors = converter.ConvertFile(targetFile, true); + + Assert.Equal(10, errors); + } + } + [Fact] public void RetainsPreprocessorInstructions() { -- cgit v1.2.3-55-g6feb