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

Adding info to debug WindowsAlternateDataStreamOverwrite failure #109399

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ public void WindowsAlternateDataStream(string defaultStream, string alternateStr
File.WriteAllText(testFile2DefaultStream, "Bar");
Assert.Throws<IOException>(() => Copy(testFile2DefaultStream, testFileAlternateStream));

try
{
Copy(testFile2DefaultStream, testFileAlternateStream);
Assert.Fail();
}
catch (IOException e)
{
// Error code for "the file exists".
Assert.Equal(-2147024816, e.HResult);
}

// This always throws as you can't copy an alternate stream out (oddly)
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2));
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2 + alternateStream));
Expand Down Expand Up @@ -352,6 +363,8 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt

// Copy the default stream into an alternate stream
File.WriteAllText(testFileDefaultStream, "Foo");
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Console.WriteLine($"Copying default stream into alternate stream.");
PranavSenthilnathan marked this conversation as resolved.
Show resolved Hide resolved
Copy(testFileDefaultStream, testFileAlternateStream);
Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Expand All @@ -361,6 +374,11 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt
string testFile2 = Path.Combine(testDirectory.FullName, GetTestFileName());
string testFile2DefaultStream = testFile2 + defaultStream;
File.WriteAllText(testFile2DefaultStream, "Bar");
Assert.Equal("Bar", File.ReadAllText(testFile2DefaultStream));
Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream));
Console.WriteLine($"Attributes for {testFile2DefaultStream}:{File.GetAttributes(testFile2DefaultStream)}");
Console.WriteLine($"Attributes for {testFileAlternateStream}:{File.GetAttributes(testFileAlternateStream)}");
Console.WriteLine($"Overwriting alternate stream.");
Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream));
Expand Down
Loading