Skip to content

Commit 8102008

Browse files
committed
Add tests for Windows Alternate Data Streams per #24
1 parent b2b9ebd commit 8102008

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

exe/CoWCloneFile.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="CommandLineParser" Version="2.8.0" />
12+
<PackageReference Include="CommandLineParser" Version="2.9.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.400",
4-
"rollForward": "feature"
3+
"version": "6.0",
4+
"rollForward": "minor"
55
}
66
}

tests/benchmark/CoWBenchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
10+
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

tests/unit/Windows/CopyOnWriteTests_Windows.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel;
67
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
@@ -133,6 +134,35 @@ public async Task ReFSPositiveDetectionAndCloneFileCorrectBehavior(CloneFlags cl
133134
string dest2Contents = await File.ReadAllTextAsync(dest2Path);
134135
Assert.AreEqual("AABBCCDD", dest2Contents);
135136

137+
// Clone a file with an Alternate Data Stream.
138+
string adsSource = Path.Combine(refsTestRoot, "AltDataStreamSource");
139+
var adsSourceFI = new FileInfo(adsSource);
140+
await File.WriteAllTextAsync(adsSource, "aaaaa");
141+
await File.WriteAllTextAsync(adsSource + ":x", "bbbbbbb");
142+
string adsDest = Path.Combine(refsTestRoot, "AltDataStreamDestination");
143+
cow.CloneFile(adsSource, adsDest, cloneFlags);
144+
Assert.IsTrue(File.Exists(adsDest));
145+
var adsDestFI = new FileInfo(adsDest);
146+
Assert.AreEqual(adsSourceFI.Length, adsDestFI.Length);
147+
string adsDestContents = await File.ReadAllTextAsync(adsDest);
148+
Assert.AreEqual("aaaaa", adsDestContents);
149+
Assert.IsFalse(File.Exists(adsDest + ":x"), "Expect that the alt data stream was not cloned");
150+
151+
const int ERROR_NOT_SUPPORTED = 50;
152+
try
153+
{
154+
cow.CloneFile(source1Path, adsDest + ":x", cloneFlags);
155+
Assert.Fail("Expected ERROR_NOT_SUPPORTED exception. Has cloning an alt data stream been added in newer Windows?");
156+
}
157+
catch (Win32Exception win32Ex) when (win32Ex.NativeErrorCode == ERROR_NOT_SUPPORTED)
158+
{
159+
// Expected.
160+
}
161+
catch (Exception ex)
162+
{
163+
Console.WriteLine(ex.ToString());
164+
}
165+
136166
// TODO: Clone a hardlink and symlink.
137167

138168
// Delete original file, ensure clones remain materialized.

0 commit comments

Comments
 (0)