[Deps]Upgrade System.IO.Abstractions (#35656)

* Upgrade System.IO.Abstractions to the latest stable release
This commit is contained in:
Davide Giacometti
2024-11-11 10:42:40 +01:00
committed by GitHub
parent 3d306f6177
commit 2ea9d56129
22 changed files with 70 additions and 53 deletions

View File

@@ -276,7 +276,7 @@ namespace Hosts.Tests
service.RemoveReadOnlyAttribute();
var readOnly = fileSystem.FileInfo.FromFileName(service.HostsFilePath).Attributes.HasFlag(FileAttributes.ReadOnly);
var readOnly = fileSystem.FileInfo.New(service.HostsFilePath).Attributes.HasFlag(FileAttributes.ReadOnly);
Assert.IsFalse(readOnly);
}
@@ -295,7 +295,7 @@ namespace Hosts.Tests
await service.WriteAsync("# Empty hosts file", Enumerable.Empty<Entry>());
var hidden = fileSystem.FileInfo.FromFileName(service.HostsFilePath).Attributes.HasFlag(FileAttributes.Hidden);
var hidden = fileSystem.FileInfo.New(service.HostsFilePath).Attributes.HasFlag(FileAttributes.Hidden);
Assert.IsTrue(hidden);
}
}

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
@@ -9,7 +10,7 @@ using System.IO.Abstractions;
namespace Hosts.Tests.Mocks
{
public class MockFileSystemWatcher : FileSystemWatcherBase
public partial class MockFileSystemWatcher : FileSystemWatcherBase
{
public override bool IncludeSubdirectories { get; set; }
@@ -27,26 +28,35 @@ namespace Hosts.Tests.Mocks
public override ISynchronizeInvoke SynchronizingObject { get; set; }
public override Collection<string> Filters => throw new System.NotImplementedException();
public override Collection<string> Filters => throw new NotImplementedException();
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) => default;
public override IFileSystem FileSystem => throw new NotImplementedException();
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) => default;
public override IContainer Container => throw new NotImplementedException();
public MockFileSystemWatcher(string path) => Path = path;
public override void BeginInit() => throw new NotImplementedException();
public override void EndInit() => throw new NotImplementedException();
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, TimeSpan timeout) => throw new NotImplementedException();
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) => throw new NotImplementedException();
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) => throw new NotImplementedException();
public MockFileSystemWatcher()
{
}
public MockFileSystemWatcher(string path)
{
Path = path;
}
public MockFileSystemWatcher(string path, string filter)
{
Path = path;
Filter = filter;
}
public override void BeginInit()
{
}
public override void EndInit()
{
}
}
}

View File

@@ -2,18 +2,22 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.IO.Abstractions;
namespace Hosts.Tests.Mocks
{
public class MockFileSystemWatcherFactory : IFileSystemWatcherFactory
{
public IFileSystemWatcher CreateNew() => new MockFileSystemWatcher(null);
public IFileSystem FileSystem => throw new NotImplementedException();
public IFileSystemWatcher CreateNew(string path) => new MockFileSystemWatcher(path);
public IFileSystemWatcher New() => new MockFileSystemWatcher();
public IFileSystemWatcher CreateNew(string path, string filter) => new MockFileSystemWatcher(path, filter);
public IFileSystemWatcher New(string path) => new MockFileSystemWatcher(path);
public IFileSystemWatcher FromPath(string path) => new MockFileSystemWatcher(path);
public IFileSystemWatcher New(string path, string filter) => new MockFileSystemWatcher(path, filter);
public IFileSystemWatcher Wrap(FileSystemWatcher fileSystemWatcher) => throw new NotImplementedException();
}
}

View File

@@ -52,7 +52,7 @@ namespace HostsUILib.Helpers
_hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\drivers\etc\hosts");
_fileSystemWatcher = _fileSystem.FileSystemWatcher.CreateNew();
_fileSystemWatcher = _fileSystem.FileSystemWatcher.New();
_fileSystemWatcher.Path = _fileSystem.Path.GetDirectoryName(HostsFilePath);
_fileSystemWatcher.Filter = _fileSystem.Path.GetFileName(HostsFilePath);
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
@@ -130,7 +130,7 @@ namespace HostsUILib.Helpers
throw new NotRunningElevatedException();
}
if (_fileSystem.FileInfo.FromFileName(HostsFilePath).IsReadOnly)
if (_fileSystem.FileInfo.New(HostsFilePath).IsReadOnly)
{
throw new ReadOnlyHostsException();
}
@@ -200,7 +200,7 @@ namespace HostsUILib.Helpers
}
// FileMode.OpenOrCreate is necessary to prevent UnauthorizedAccessException when the hosts file is hidden
using var stream = _fileSystem.FileStream.Create(HostsFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read, _defaultBufferSize, FileOptions.Asynchronous);
using var stream = _fileSystem.FileStream.New(HostsFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read, _defaultBufferSize, FileOptions.Asynchronous);
using var writer = new StreamWriter(stream, Encoding);
foreach (var line in lines)
{
@@ -305,7 +305,7 @@ namespace HostsUILib.Helpers
public void RemoveReadOnlyAttribute()
{
var fileInfo = _fileSystem.FileInfo.FromFileName(HostsFilePath);
var fileInfo = _fileSystem.FileInfo.New(HostsFilePath);
if (fileInfo.IsReadOnly)
{
fileInfo.IsReadOnly = false;

View File

@@ -31,7 +31,7 @@ namespace WorkspacesEditor.Utils
{
try
{
using (Stream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
using (FileSystemStream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
using (StreamReader reader = new StreamReader(inputStream))
{
string data = reader.ReadToEnd();

View File

@@ -31,7 +31,7 @@ namespace FancyZonesEditorCommon.Utils
{
try
{
using (Stream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
using (FileSystemStream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
using (StreamReader reader = new StreamReader(inputStream))
{
string data = reader.ReadToEnd();

View File

@@ -27,7 +27,11 @@ namespace Microsoft.FancyZonesEditor.UITests.Utils
}
else
{
_fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(file));
var path = Path.GetDirectoryName(file);
if (path != null)
{
_fileSystem.Directory.CreateDirectory(path);
}
}
}

View File

@@ -421,7 +421,7 @@ namespace ImageResizer.Properties
string jsonData = JsonSerializer.Serialize(new SettingsWrapper() { Properties = this }, _jsonSerializerOptions);
// Create directory if it doesn't exist
IFileInfo file = _fileSystem.FileInfo.FromFileName(SettingsPath);
IFileInfo file = _fileSystem.FileInfo.New(SettingsPath);
file.Directory.Create();
// write string to file

View File

@@ -51,7 +51,7 @@ namespace Microsoft.Plugin.Folder.UnitTests
[DataRow(@"c:", 2, 1, false, DisplayName = "Root without \\")]
[DataRow(@"c:\", 2, 1, false, DisplayName = "Normal root")]
[DataRow(@"c:\Test", 2, 2, false, DisplayName = "Select yourself")]
[DataRow(@"c:\not-exist", 2, 1, false, DisplayName = "Folder not exist, return root")]
[DataRow(@"c:\not-exist", 2, 0, false, DisplayName = "Folder not exist, return root")]
[DataRow(@"c:\not-exist\not-exist2", 0, 0, false, DisplayName = "Folder not exist, return root")]
[DataRow(@"c:\bla.t", 2, 1, false, DisplayName = "Partial match file")]
[DataRow(@"c:/bla.t", 2, 1, false, DisplayName = "Partial match file with /")]
@@ -88,8 +88,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
[DataTestMethod]
[DataRow(@"c:\>", 3, 3, true, DisplayName = "Max Folder test recursive")]
[DataRow(@"c:\Test>", 3, 3, true, DisplayName = "2 Folders recursive")]
[DataRow(@"c:\not-exist>", 3, 3, true, DisplayName = "Folder not exist, return root recursive")]
[DataRow(@"c:\Test>", 3, 0, true, DisplayName = "2 Folders recursive")]
[DataRow(@"c:\not-exist>", 3, 0, true, DisplayName = "Folder not exist, return root recursive")]
[DataRow(@"c:\not-exist\not-exist2>", 0, 0, false, DisplayName = "Folder not exist, return root recursive")]
public void Query_Recursive_WhenCalled(string search, int folders, int files, bool truncated)
{

View File

@@ -25,7 +25,7 @@ namespace Microsoft.Plugin.Folder.Sources
public IEnumerable<DisplayFileInfo> MatchFileSystemInfo(string search, string incompleteName, bool isRecursive)
{
// search folder and add results
var directoryInfo = _directoryInfoFactory.FromDirectoryName(search);
var directoryInfo = _directoryInfoFactory.New(search);
var fileSystemInfos = directoryInfo.EnumerateFileSystemInfos(incompleteName, new EnumerationOptions
{
MatchType = _matchType,

View File

@@ -22,7 +22,7 @@ namespace Microsoft.Plugin.Program
public string Location { get; set; }
public string Name { get => name ?? FileSystem.DirectoryInfo.FromDirectoryName(Location).Name; set => name = value; }
public string Name { get => name ?? FileSystem.DirectoryInfo.New(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;

View File

@@ -71,8 +71,8 @@ namespace Wox.Infrastructure
}
else
{
var time1 = FileInfo.FromFileName(bundledDataPath).LastWriteTimeUtc;
var time2 = FileInfo.FromFileName(dataPath).LastWriteTimeUtc;
var time1 = FileInfo.New(bundledDataPath).LastWriteTimeUtc;
var time2 = FileInfo.New(dataPath).LastWriteTimeUtc;
if (time1 != time2)
{
File.Copy(bundledDataPath, dataPath, true);