From 8102008b8ae24e1f12038084292706bbd3bee791 Mon Sep 17 00:00:00 2001 From: "Erik Mavrinac (from Dev Box)" Date: Tue, 27 Jun 2023 16:17:49 -0700 Subject: [PATCH] Add tests for Windows Alternate Data Streams per #24 --- exe/CoWCloneFile.csproj | 2 +- global.json | 4 +-- tests/benchmark/CoWBenchmark.csproj | 2 +- .../unit/Windows/CopyOnWriteTests_Windows.cs | 30 +++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/exe/CoWCloneFile.csproj b/exe/CoWCloneFile.csproj index 0148517..93e1409 100644 --- a/exe/CoWCloneFile.csproj +++ b/exe/CoWCloneFile.csproj @@ -9,7 +9,7 @@ - + diff --git a/global.json b/global.json index 4e3dc8a..585f8d0 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.400", - "rollForward": "feature" + "version": "6.0", + "rollForward": "minor" } } diff --git a/tests/benchmark/CoWBenchmark.csproj b/tests/benchmark/CoWBenchmark.csproj index 06b92a8..324f395 100644 --- a/tests/benchmark/CoWBenchmark.csproj +++ b/tests/benchmark/CoWBenchmark.csproj @@ -7,7 +7,7 @@ - + diff --git a/tests/unit/Windows/CopyOnWriteTests_Windows.cs b/tests/unit/Windows/CopyOnWriteTests_Windows.cs index 23e69c1..d5161b3 100644 --- a/tests/unit/Windows/CopyOnWriteTests_Windows.cs +++ b/tests/unit/Windows/CopyOnWriteTests_Windows.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -133,6 +134,35 @@ public async Task ReFSPositiveDetectionAndCloneFileCorrectBehavior(CloneFlags cl string dest2Contents = await File.ReadAllTextAsync(dest2Path); Assert.AreEqual("AABBCCDD", dest2Contents); + // Clone a file with an Alternate Data Stream. + string adsSource = Path.Combine(refsTestRoot, "AltDataStreamSource"); + var adsSourceFI = new FileInfo(adsSource); + await File.WriteAllTextAsync(adsSource, "aaaaa"); + await File.WriteAllTextAsync(adsSource + ":x", "bbbbbbb"); + string adsDest = Path.Combine(refsTestRoot, "AltDataStreamDestination"); + cow.CloneFile(adsSource, adsDest, cloneFlags); + Assert.IsTrue(File.Exists(adsDest)); + var adsDestFI = new FileInfo(adsDest); + Assert.AreEqual(adsSourceFI.Length, adsDestFI.Length); + string adsDestContents = await File.ReadAllTextAsync(adsDest); + Assert.AreEqual("aaaaa", adsDestContents); + Assert.IsFalse(File.Exists(adsDest + ":x"), "Expect that the alt data stream was not cloned"); + + const int ERROR_NOT_SUPPORTED = 50; + try + { + cow.CloneFile(source1Path, adsDest + ":x", cloneFlags); + Assert.Fail("Expected ERROR_NOT_SUPPORTED exception. Has cloning an alt data stream been added in newer Windows?"); + } + catch (Win32Exception win32Ex) when (win32Ex.NativeErrorCode == ERROR_NOT_SUPPORTED) + { + // Expected. + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + // TODO: Clone a hardlink and symlink. // Delete original file, ensure clones remain materialized.