Skip to content

Commit

Permalink
[Deps]Upgrade System.IO.Abstractions (#35656)
Browse files Browse the repository at this point in the history
* Upgrade System.IO.Abstractions to the latest stable release
  • Loading branch information
davidegiacometti authored Nov 11, 2024
1 parent 3d306f6 commit 2ea9d56
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .pipelines/ESRPSigning_core.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@
"WinUI3Apps\\ReverseMarkdown.dll",
"WinUI3Apps\\SharpCompress.dll",
"WinUI3Apps\\ZstdSharp.dll",
"TestableIO.System.IO.Abstractions.dll",
"WinUI3Apps\\TestableIO.System.IO.Abstractions.dll",
"TestableIO.System.IO.Abstractions.Wrappers.dll",
"WinUI3Apps\\TestableIO.System.IO.Abstractions.Wrappers.dll",
"ColorCode.Core.dll",
"ColorCode.UWP.dll",
"UnitsNet.dll",
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<!-- Package System.Diagnostics.EventLog added as a hack for being able to exclude the runtime assets so they don't conflict with 8.0.1. This is a dependency of System.Data.OleDb but the 8.0.1 version wasn't published to nuget. -->
<PackageVersion Include="System.Diagnostics.EventLog" Version="8.0.1" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.7" />
<PackageVersion Include="System.IO.Abstractions" Version="17.2.3" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.1" />
Expand Down
4 changes: 2 additions & 2 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ EXHIBIT A -Mozilla Public License.
- System.Data.SqlClient 4.8.6
- System.Diagnostics.EventLog 8.0.1
- System.Drawing.Common 8.0.7
- System.IO.Abstractions 17.2.3
- System.IO.Abstractions.TestingHelpers 17.2.3
- System.IO.Abstractions 21.0.29
- System.IO.Abstractions.TestingHelpers 21.0.29
- System.Management 8.0.0
- System.Reactive 6.0.1
- System.Runtime.Caching 8.0.1
Expand Down
6 changes: 2 additions & 4 deletions src/common/ManagedCommon/LanguageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.IO;
using System.IO.Abstractions;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand All @@ -23,15 +22,14 @@ internal sealed class OutGoingLanguageSettings

public static string LoadLanguage()
{
FileSystem fileSystem = new FileSystem();
var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var file = localAppDataDir + SettingsFilePath + SettingsFile;

if (fileSystem.File.Exists(file))
if (File.Exists(file))
{
try
{
Stream inputStream = fileSystem.File.Open(file, FileMode.Open);
var inputStream = File.Open(file, FileMode.Open);
StreamReader reader = new StreamReader(inputStream);
string data = reader.ReadToEnd();
inputStream.Close();
Expand Down
9 changes: 4 additions & 5 deletions src/common/ManagedCommon/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO.Abstractions;
using System.IO;
using System.Reflection;

using PowerToys.Interop;
Expand All @@ -14,7 +14,6 @@ namespace ManagedCommon
{
public static class Logger
{
private static readonly IFileSystem _fileSystem = new FileSystem();
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;

Expand All @@ -41,12 +40,12 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow =
applicationLogPath = Constants.AppDataPath() + applicationLogPath + "\\" + Version;
}

if (!_fileSystem.Directory.Exists(applicationLogPath))
if (!Directory.Exists(applicationLogPath))
{
_fileSystem.Directory.CreateDirectory(applicationLogPath);
Directory.CreateDirectory(applicationLogPath);
}

var logFilePath = _fileSystem.Path.Combine(applicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
var logFilePath = Path.Combine(applicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");

Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));

Expand Down
1 change: 0 additions & 1 deletion src/common/ManagedCommon/ManagedCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="System.Management" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/modules/Hosts/Hosts.Tests/HostsServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void Remove_ReadOnly_Attribute()

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);
}

Expand All @@ -295,7 +295,7 @@ public async Task Save_Hidden_Hosts()

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);
}
}
Expand Down
30 changes: 20 additions & 10 deletions src/modules/Hosts/Hosts.Tests/Mocks/MockFileSystemWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// 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;
using System.IO.Abstractions;

namespace Hosts.Tests.Mocks
{
public class MockFileSystemWatcher : FileSystemWatcherBase
public partial class MockFileSystemWatcher : FileSystemWatcherBase
{
public override bool IncludeSubdirectories { get; set; }

Expand All @@ -27,26 +28,35 @@ public class MockFileSystemWatcher : FileSystemWatcherBase

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 MockFileSystemWatcher(string path, string filter)
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()
{
Path = path;
Filter = filter;
}

public override void BeginInit()
public MockFileSystemWatcher(string path)
{
Path = path;
}

public override void EndInit()
public MockFileSystemWatcher(string path, string filter)
{
Path = path;
Filter = filter;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions src/modules/Hosts/HostsUILib/Helpers/HostsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public HostsService(

_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;
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task WriteAsync(string additionalLines, IEnumerable<Entry> entries)
throw new NotRunningElevatedException();
}

if (_fileSystem.FileInfo.FromFileName(HostsFilePath).IsReadOnly)
if (_fileSystem.FileInfo.New(HostsFilePath).IsReadOnly)
{
throw new ReadOnlyHostsException();
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task WriteAsync(string additionalLines, IEnumerable<Entry> entries)
}

// 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)
{
Expand Down Expand Up @@ -305,7 +305,7 @@ public void OpenHostsFile()

public void RemoveReadOnlyAttribute()
{
var fileInfo = _fileSystem.FileInfo.FromFileName(HostsFilePath);
var fileInfo = _fileSystem.FileInfo.New(HostsFilePath);
if (fileInfo.IsReadOnly)
{
fileInfo.IsReadOnly = false;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Workspaces/WorkspacesEditor/Utils/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string ReadFile(string fileName)
{
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string ReadFile(string fileName)
{
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public IOTestHelper(string file)
}
else
{
_fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(file));
var path = Path.GetDirectoryName(file);
if (path != null)
{
_fileSystem.Directory.CreateDirectory(path);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/imageresizer/ui/Properties/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void Save()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Query_ThrowsException_WhenCalledNull()
[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 /")]
Expand Down Expand Up @@ -88,8 +88,8 @@ public void Query_WhenCalled(string search, int folders, int files, bool truncat

[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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public QueryFileSystemInfo(IDirectoryInfoFactory directoryInfoFactory, MatchType
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProgramSource

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;

Expand Down
4 changes: 2 additions & 2 deletions src/modules/launcher/Wox.Infrastructure/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static void ValidateDataDirectory(string bundledDataDirectory, string dat
}
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);
Expand Down
2 changes: 1 addition & 1 deletion src/settings-ui/Settings.UI.Library/LanguageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static string LoadSetting()
{
try
{
Stream inputStream = fileSystem.File.Open(file, FileMode.Open);
FileSystemStream inputStream = fileSystem.File.Open(file, FileMode.Open);
StreamReader reader = new StreamReader(inputStream);
string data = reader.ReadToEnd();
inputStream.Close();
Expand Down
2 changes: 1 addition & 1 deletion src/settings-ui/Settings.UI.Library/UpdatingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static UpdatingSettings LoadSettings()
{
try
{
Stream inputStream = fileSystem.File.Open(file, FileMode.Open);
FileSystemStream inputStream = fileSystem.File.Open(file, FileMode.Open);
StreamReader reader = new StreamReader(inputStream);
string data = reader.ReadToEnd();
inputStream.Close();
Expand Down
3 changes: 1 addition & 2 deletions src/settings-ui/Settings.UI.Library/Utilities/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.Principal;

using Microsoft.PowerToys.Settings.UI.Library.CustomAction;
Expand Down Expand Up @@ -63,7 +62,7 @@ public static IFileSystemWatcher GetFileWatcher(string moduleName, string fileNa
FileSystem.Directory.CreateDirectory(path);
}

var watcher = FileSystem.FileSystemWatcher.CreateNew();
var watcher = FileSystem.FileSystemWatcher.New();
watcher.Path = path;
watcher.Filter = fileName;
watcher.NotifyFilter = NotifyFilters.LastWrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AwakePage()

var settingsPath = _settingsUtils.GetSettingsFilePath(_appName);

_fileSystemWatcher = _fileSystem.FileSystemWatcher.CreateNew();
_fileSystemWatcher = _fileSystem.FileSystemWatcher.New();
_fileSystemWatcher.Path = _fileSystem.Path.GetDirectoryName(settingsPath);
_fileSystemWatcher.Filter = _fileSystem.Path.GetFileName(settingsPath);
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime;
Expand Down

0 comments on commit 2ea9d56

Please sign in to comment.