Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Windows Alternate Data Streams #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading