From 79fafd049e556f9b108ce726178d543683bfcf9d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 05:40:13 +0000 Subject: [PATCH 1/7] chore(deps): update dependency awexpect to 2.2.0 (#1261) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f55312b4c..de94b3a0e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -19,7 +19,7 @@ - + From 4e3c7dfddf98c50cfcd2a8a0b2e10924f16af534 Mon Sep 17 00:00:00 2001 From: William Moy <3392824+wimoy@users.noreply.github.com> Date: Tue, 8 Apr 2025 06:52:16 -0700 Subject: [PATCH 2/7] fix: Add missing lock around files dictionary (#1260) Add missing lock around files variable The files dictionary could be modified and resized by another thread. Without the lock, the read is not synchronized and can cause a KeyNotFoundException. --- .../MockFileSystem.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index 8b1b620a2..3f71206cb 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -156,7 +156,12 @@ private string GetPathWithCorrectDirectoryCapitalization(string fullPath) if (DirectoryExistsWithoutFixingPath(leftHalf)) { - string baseDirectory = files[leftHalf].Path; + string baseDirectory; + lock (files) + { + baseDirectory = files[leftHalf].Path; + } + return baseDirectory + Path.DirectorySeparatorChar + rightHalf; } } @@ -581,4 +586,4 @@ private class FileSystemEntry public string Path { get; set; } public MockFileData Data { get; set; } } -} \ No newline at end of file +} From b0e9d4e46a58eceee06bbec4f3bf03d62766c1d8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:58:43 +0000 Subject: [PATCH 3/7] chore(deps): update dependency system.text.json to 9.0.4 (#1262) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index de94b3a0e..5ff3b11df 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,7 +4,7 @@ - + From 86acad37a87b3d62cb8bc17f076321db43bb43b2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 9 Apr 2025 17:31:49 +0000 Subject: [PATCH 4/7] chore(deps): update dependency dotnet-sdk to v9.0.203 (#1263) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 016e6ccd1..d8052df1b 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.202", + "version": "9.0.203", "rollForward": "latestMinor" } } From 5d32890e4505194af671434535b7f126a49affe8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 13 Apr 2025 01:30:22 +0000 Subject: [PATCH 5/7] chore(deps): update dependency awexpect to 2.3.1 (#1264) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5ff3b11df..ce03362c8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -19,7 +19,7 @@ - + From 84843b84c75bf348ea2c1e3831784fbafb72da7e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 15 Apr 2025 08:03:17 +0000 Subject: [PATCH 6/7] chore(deps): update dependency awexpect to 2.4.0 (#1265) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index ce03362c8..949d6b699 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -19,7 +19,7 @@ - + From 2c9258904ae036c0ab8b8dd5f0758f0316fa2c66 Mon Sep 17 00:00:00 2001 From: Sinchan Saha <95886540+oni-shiro@users.noreply.github.com> Date: Sat, 19 Apr 2025 01:28:11 +0530 Subject: [PATCH 7/7] fix: `Directory.Move` fails on Windows if destination has different case from source (#1256) On Windows, `MockFileSystem.Directory.Move` no longer throws a `System.IO.IOException` when source and destination path only differ in casing. --- .../MockDirectory.cs | 14 +++++++++----- .../MockDirectoryTests.cs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 5b9e7968b..242bb0d5e 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -503,7 +503,7 @@ public override void Move(string sourceDirName, string destDirName) var fullSourcePath = mockFileDataAccessor.Path.GetFullPath(sourceDirName).TrimSlashes(); var fullDestPath = mockFileDataAccessor.Path.GetFullPath(destDirName).TrimSlashes(); - if (mockFileDataAccessor.StringOperations.Equals(fullSourcePath, fullDestPath)) + if (string.Equals(fullSourcePath, fullDestPath, StringComparison.Ordinal)) { throw new IOException("Source and destination path must be different."); } @@ -537,9 +537,13 @@ public override void Move(string sourceDirName, string destDirName) if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath)) { - throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath); + // In Windows, file/dir names are case sensetive, C:\\temp\\src and C:\\temp\\SRC and treated different + if (XFS.IsUnixPlatform() || + !string.Equals(fullSourcePath, fullDestPath, StringComparison.OrdinalIgnoreCase)) + { + throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath); + } } - mockFileDataAccessor.MoveDirectory(fullSourcePath, fullDestPath); } @@ -653,7 +657,7 @@ public override IEnumerable EnumerateDirectories(string path, string sea .Where(p => !mockFileDataAccessor.StringOperations.Equals(p, path)) .Select(p => FixPrefix(p, originalPath)); } - + private string FixPrefix(string path, string originalPath) { var normalizedOriginalPath = mockFileDataAccessor.Path.GetFullPath(originalPath); @@ -661,7 +665,7 @@ private string FixPrefix(string path, string originalPath) .TrimStart(mockFileDataAccessor.Path.DirectorySeparatorChar); return mockFileDataAccessor.Path.Combine(originalPath, pathWithoutOriginalPath); } - + #if FEATURE_ENUMERATION_OPTIONS /// public override IEnumerable EnumerateDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 3a0711ff3..fae8b65a3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -2204,4 +2204,19 @@ public async Task MockDirectory_Exists_ShouldReturnTrue_IfArgIsFrontSlashAndRoot await That(fileSystem.Directory.Exists("/")).IsEqualTo(true); } + + [Test] + public static void MockDirectory_Move_ShouldNotThrowException_InWindows_When_SourceAndDestinationDifferOnlyInCasing() + { + // Arrange + MockFileSystem mockFs = new MockFileSystem(); + string tempDir = mockFs.Path.GetTempPath(); + string src = mockFs.Path.Combine(tempDir, "src"); + string dest = mockFs.Path.Combine(tempDir, "SRC"); + IDirectoryInfo srcDir = mockFs.DirectoryInfo.New(src); + srcDir.Create(); + + // Act & Assert + Assert.DoesNotThrow(() => mockFs.Directory.Move(src, dest)); + } } \ No newline at end of file