diff --git a/src/Sarif.Multitool.Library/AbsoluteUriCommand.cs b/src/Sarif.Multitool.Library/AbsoluteUriCommand.cs index 3eb6a62fc..b4bf56043 100644 --- a/src/Sarif.Multitool.Library/AbsoluteUriCommand.cs +++ b/src/Sarif.Multitool.Library/AbsoluteUriCommand.cs @@ -30,7 +30,7 @@ public int Run(AbsoluteUriOptions absoluteUriOptions) if (!absoluteUriOptions.Inline) { - _fileSystem.CreateDirectory(absoluteUriOptions.OutputDirectoryPath); + _fileSystem.DirectoryCreate(absoluteUriOptions.OutputDirectoryPath); } Formatting formatting = absoluteUriOptions.PrettyPrint diff --git a/src/Sarif.Multitool.Library/CommandBase.cs b/src/Sarif.Multitool.Library/CommandBase.cs index e70bd98e8..0673311a0 100644 --- a/src/Sarif.Multitool.Library/CommandBase.cs +++ b/src/Sarif.Multitool.Library/CommandBase.cs @@ -52,7 +52,7 @@ public static void WriteSarifFile(IFileSystem fileSystem, T sarifFile, string Formatting = formatting }; - using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter(fileSystem.Create(outputName)))) + using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter(fileSystem.FileCreate(outputName)))) { serializer.Serialize(writer, sarifFile); } diff --git a/src/Sarif.Multitool.Library/MergeCommand.cs b/src/Sarif.Multitool.Library/MergeCommand.cs index 0ecf9f9cb..3c647b80b 100644 --- a/src/Sarif.Multitool.Library/MergeCommand.cs +++ b/src/Sarif.Multitool.Library/MergeCommand.cs @@ -61,7 +61,7 @@ public int Run(MergeOptions mergeOptions) ? Formatting.Indented : Formatting.None; - _fileSystem.CreateDirectory(outputDirectory); + _fileSystem.DirectoryCreate(outputDirectory); WriteSarifFile(_fileSystem, mergedLog, outputFilePath, formatting); return 0; @@ -124,7 +124,7 @@ public int Run(MergeOptions mergeOptions) ? Formatting.Indented : Formatting.None; - _fileSystem.CreateDirectory(outputDirectory); + _fileSystem.DirectoryCreate(outputDirectory); outputFilePath = Path.Combine(outputDirectory, GetOutputFileName(mergeOptions, ruleId)); diff --git a/src/Sarif.Multitool.Library/PageCommand.cs b/src/Sarif.Multitool.Library/PageCommand.cs index 80a5b022f..6ae791576 100644 --- a/src/Sarif.Multitool.Library/PageCommand.cs +++ b/src/Sarif.Multitool.Library/PageCommand.cs @@ -195,7 +195,7 @@ private void ExtractPage(PageOptions options, JsonMapNode root) long lengthWritten = 0; byte[] buffer = new byte[64 * 1024]; - using (Stream output = _fileSystem.Create(options.OutputFilePath)) + using (Stream output = _fileSystem.FileCreate(options.OutputFilePath)) using (Stream source = _fileSystem.OpenRead(options.InputFilePath)) { // Copy everything up to 'runs' (includes the '[') diff --git a/src/Sarif.Multitool.Library/RebaseUriCommand.cs b/src/Sarif.Multitool.Library/RebaseUriCommand.cs index cfbd8cf73..6a6cb8d30 100644 --- a/src/Sarif.Multitool.Library/RebaseUriCommand.cs +++ b/src/Sarif.Multitool.Library/RebaseUriCommand.cs @@ -44,7 +44,7 @@ public int Run(RebaseUriOptions rebaseOptions) if (!rebaseOptions.Inline) { - _fileSystem.CreateDirectory(rebaseOptions.OutputDirectoryPath); + _fileSystem.DirectoryCreate(rebaseOptions.OutputDirectoryPath); } Formatting formatting = rebaseOptions.PrettyPrint diff --git a/src/Sarif.Multitool.Library/ResultMatchSetCommand.cs b/src/Sarif.Multitool.Library/ResultMatchSetCommand.cs index d8ad469bf..7338ebfaf 100644 --- a/src/Sarif.Multitool.Library/ResultMatchSetCommand.cs +++ b/src/Sarif.Multitool.Library/ResultMatchSetCommand.cs @@ -34,11 +34,11 @@ public int Run(ResultMatchSetOptions options) // Remove previous results. if (_fileSystem.DirectoryExists(options.OutputFolderPath) && options.Force) { - _fileSystem.DeleteDirectory(options.OutputFolderPath, true); + _fileSystem.DirectoryDelete(options.OutputFolderPath, true); } // Create output folder. - _fileSystem.CreateDirectory(options.OutputFolderPath); + _fileSystem.DirectoryCreate(options.OutputFolderPath); string previousFileName = ""; string previousGroup = ""; diff --git a/src/Sarif/FileSystem.cs b/src/Sarif/FileSystem.cs index bc0628a31..edfc50534 100644 --- a/src/Sarif/FileSystem.cs +++ b/src/Sarif/FileSystem.cs @@ -221,7 +221,7 @@ public Stream OpenRead(string path) /// /// File System path of file to open /// Stream to write file - public Stream Create(string path) + public Stream FileCreate(string path) { return File.Create(path); } @@ -251,7 +251,7 @@ public void SetAttributes(string path, FileAttributes fileAttributes) /// An object that represents the directory at the specified path. This object is /// returned regardless of whether a directory at the specified path already exists. /// - public DirectoryInfo CreateDirectory(string path) + public DirectoryInfo DirectoryCreate(string path) { return Directory.CreateDirectory(path); } @@ -262,9 +262,20 @@ public DirectoryInfo CreateDirectory(string path) /// /// The name of the empty directory to remove. This directory must be writable and empty. /// - public void DeleteDirectory(string path, bool recursive = false) + public void DirectoryDelete(string path, bool recursive = false) { Directory.Delete(path, recursive); } + + /// + /// Deletes the specified file. + /// + /// + /// The name of the file to be deleted. Wildcard characters are not supported. + /// + public void FileDelete(string path) + { + File.Delete(path); + } } } diff --git a/src/Sarif/IFileSystem.cs b/src/Sarif/IFileSystem.cs index 70e0b7e5b..42837f07d 100644 --- a/src/Sarif/IFileSystem.cs +++ b/src/Sarif/IFileSystem.cs @@ -184,7 +184,7 @@ public interface IFileSystem /// /// File System path of file to open /// Stream to write file - Stream Create(string path); + Stream FileCreate(string path); /// /// Sets the specified of the file on the specified path. @@ -208,7 +208,7 @@ public interface IFileSystem /// An object that represents the directory at the specified path. This object is /// returned regardless of whether a directory at the specified path already exists. /// - DirectoryInfo CreateDirectory(string path); + DirectoryInfo DirectoryCreate(string path); /// /// Deletes an empty directory from a specified path. @@ -216,6 +216,14 @@ public interface IFileSystem /// /// The name of the empty directory to remove. This directory must be writable and empty. /// - void DeleteDirectory(string path, bool recursive = false); + void DirectoryDelete(string path, bool recursive = false); + + /// + /// Deletes the specified file. + /// + /// + /// The name of the file to be deleted. Wildcard characters are not supported. + /// + void FileDelete(string path); } } diff --git a/src/Test.UnitTests.Sarif.Multitool.Library/MergeCommandTests.cs b/src/Test.UnitTests.Sarif.Multitool.Library/MergeCommandTests.cs index 929ae7213..dcbf14aae 100644 --- a/src/Test.UnitTests.Sarif.Multitool.Library/MergeCommandTests.cs +++ b/src/Test.UnitTests.Sarif.Multitool.Library/MergeCommandTests.cs @@ -53,8 +53,8 @@ protected override string ConstructTestOutputFromInputResource(string inputResou mockFileSystem.Setup(x => x.GetFilesInDirectory(InputFolderPath, inputResourceName)).Returns(new string[0]); // <= The hard-coded return value in question. // But we really do want to create the output file, so tell the mock to execute the actual write operations. - mockFileSystem.Setup(x => x.CreateDirectory(OutputFolderPath)).Returns((string path) => { return Directory.CreateDirectory(path); }); - mockFileSystem.Setup(x => x.Create(outputFilePath)).Returns((string path) => { return File.Create(path); }); + mockFileSystem.Setup(x => x.DirectoryCreate(OutputFolderPath)).Returns((string path) => { return Directory.CreateDirectory(path); }); + mockFileSystem.Setup(x => x.FileCreate(outputFilePath)).Returns((string path) => { return File.Create(path); }); IFileSystem fileSystem = mockFileSystem.Object; diff --git a/src/Test.UnitTests.Sarif.Multitool.Library/RebaseUriCommandTests.cs b/src/Test.UnitTests.Sarif.Multitool.Library/RebaseUriCommandTests.cs index c4dda1476..6bb628782 100644 --- a/src/Test.UnitTests.Sarif.Multitool.Library/RebaseUriCommandTests.cs +++ b/src/Test.UnitTests.Sarif.Multitool.Library/RebaseUriCommandTests.cs @@ -154,7 +154,7 @@ private static Mock ArrangeMockFileSystem(string sarifLog, string l var mockFileSystem = new Mock(); mockFileSystem.Setup(x => x.ReadAllText(logFilePath)).Returns(sarifLog); mockFileSystem.Setup(x => x.OpenRead(logFilePath)).Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(sarifLog))); - mockFileSystem.Setup(x => x.Create(logFilePath)).Returns(() => new MemoryStreamToStringBuilder(transformedContents)); + mockFileSystem.Setup(x => x.FileCreate(logFilePath)).Returns(() => new MemoryStreamToStringBuilder(transformedContents)); mockFileSystem.Setup(x => x.WriteAllText(logFilePath, It.IsAny())).Callback((path, contents) => { transformedContents.Append(contents); }); mockFileSystem.Setup(x => x.DirectoryExists(It.IsAny())).Returns(true); mockFileSystem.Setup(x => x.GetFilesInDirectory(It.IsAny(), It.IsAny())).Returns(new string[] { logFilePath }); diff --git a/src/Test.UnitTests.Sarif.Multitool.Library/TransformCommandTests.cs b/src/Test.UnitTests.Sarif.Multitool.Library/TransformCommandTests.cs index 5915e14e5..66594c1b2 100644 --- a/src/Test.UnitTests.Sarif.Multitool.Library/TransformCommandTests.cs +++ b/src/Test.UnitTests.Sarif.Multitool.Library/TransformCommandTests.cs @@ -160,7 +160,7 @@ private static string RunTransformationCore(string logFileContents, SarifVersion var mockFileSystem = new Mock(); mockFileSystem.Setup(x => x.ReadAllText(LogFilePath)).Returns(logFileContents); mockFileSystem.Setup(x => x.OpenRead(LogFilePath)).Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(logFileContents))); - mockFileSystem.Setup(x => x.Create(LogFilePath)).Returns(() => new MemoryStreamToStringBuilder(transformedContents)); + mockFileSystem.Setup(x => x.FileCreate(LogFilePath)).Returns(() => new MemoryStreamToStringBuilder(transformedContents)); mockFileSystem.Setup(x => x.WriteAllText(LogFilePath, It.IsAny())).Callback((path, contents) => { transformedContents.Append(contents); }); var transformCommand = new TransformCommand(mockFileSystem.Object);