Skip to content

Commit

Permalink
Add tests for Windows Alternate Data Streams per #24
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmav committed Oct 31, 2023
1 parent b2b9ebd commit 8102008
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion exe/CoWCloneFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.400",
"rollForward": "feature"
"version": "6.0",
"rollForward": "minor"
}
}
2 changes: 1 addition & 1 deletion tests/benchmark/CoWBenchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/Windows/CopyOnWriteTests_Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8102008

Please sign in to comment.