Detect Inability to write to output file
Fixes wixtoolset/issues#6425
Ron Martin committed
Apr 22, 2021 at 18:46 UTC
b0840f6ad872f7085fd8d62285dc889763a65968
2 files changed
+35
-9
src/WixToolset.Converters/WixConverter.cs
+11
-9
@@ -1848,8 +1848,8 @@ namespace WixToolset.Converters
1848
{
1849
// Ignore the error if explicitly ignored or outside the range of the current operation.
1850
if (this.IgnoreErrors.Contains(converterTestType) ||
1851
- (this.Operation == ConvertOperation.Convert && converterTestType < ConverterTestType.DeclarationPresent) ||
1852
- (this.Operation == ConvertOperation.Format && converterTestType > ConverterTestType.DeclarationPresent))
1851
+ (this.Operation == ConvertOperation.Convert && converterTestType < ConverterTestType.EndIgnoreInConvert) ||
1852
+ (this.Operation == ConvertOperation.Format && converterTestType > ConverterTestType.BeginIgnoreInFormat))
1853
{
1854
return false;
1855
}
@@ -2032,11 +2032,6 @@ namespace WixToolset.Converters
2032
/// </summary>
2033
XmlException,
2034
2035
- /// <summary>
2036
- /// Displayed when a file cannot be accessed; typically when trying to save back a fixed file.
2037
- /// </summary>
2038
- UnauthorizedAccessException,
2039
-
2035
/// <summary>
2036
/// Displayed when the whitespace preceding a node is wrong.
2037
/// </summary>
@@ -2047,14 +2042,21 @@ namespace WixToolset.Converters
2042
/// </summary>
2043
WhitespacePrecedingEndElementWrong,
2044
2050
- // Before this point, ignore errors on convert operation
2045
+ /// Before this point, ignore errors on convert operation
2046
+ EndIgnoreInConvert,
2047
2048
/// <summary>
2049
/// Displayed when the XML declaration is present in the source file.
2050
/// </summary>
2051
DeclarationPresent,
2052
2057
- // After this point, ignore errors on format operation
2053
+ /// <summary>
2054
+ /// Displayed when a file cannot be accessed; typically when trying to save back a fixed file.
2055
+ /// </summary>
2056
+ UnauthorizedAccessException,
2057
+
2058
+ /// After this point, ignore errors on format operation
2059
+ BeginIgnoreInFormat,
2060
2061
/// <summary>
2062
/// Displayed when the xmlns attribute is missing from the document element.
src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs
+24
@@ -8,6 +8,7 @@ namespace WixToolsetTest.Converters
8
using WixBuildTools.TestSupport;
9
using WixToolset.Converters;
10
using WixToolset.Core;
11
+ using WixToolset.Core.ExtensibilityServices;
12
using WixToolset.Core.TestPackage;
13
using WixToolsetTest.Converters.Mocks;
14
using Xunit;
@@ -68,6 +69,29 @@ namespace WixToolsetTest.Converters
69
}
70
}
71
72
+ [Fact]
73
+ public void CanDetectReadOnlyOutputFile()
74
+ {
75
+ const string beforeFileName = "SingleFile.wxs";
76
+ var folder = TestData.Get(@"TestData\SingleFile");
77
+
78
+ using (var fs = new DisposableFileSystem())
79
+ {
80
+ var baseFolder = fs.GetFolder(true);
81
+ var targetFile = Path.Combine(baseFolder, beforeFileName);
82
+ File.Copy(Path.Combine(folder, beforeFileName), Path.Combine(baseFolder, beforeFileName));
83
+
84
+ var info = new FileInfo(targetFile);
85
+ info.IsReadOnly = true;
86
+
87
+ var messaging = new MockMessaging();
88
+ var converter = new WixConverter(messaging, 4);
89
+ var errors = converter.ConvertFile(targetFile, true);
90
+
91
+ Assert.Equal(10, errors);
92
+ }
93
+ }
94
+
95
[Fact]
96
public void RetainsPreprocessorInstructions()
97
{