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
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Security.Cryptography;
using Xunit;
using Xunit.Abstractions;

namespace System.IO.Tests
{
Expand Down Expand Up @@ -236,6 +237,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 @@ -275,6 +287,12 @@ public void OverwriteCopyOntoLink()

public class File_Copy_str_str_b : File_Copy_str_str
{
private ITestOutputHelper _output;
public File_Copy_str_str_b(ITestOutputHelper output)
{
_output = output;
}

protected override void Copy(string source, string dest)
{
File.Copy(source, dest, false);
Expand Down Expand Up @@ -352,6 +370,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));
_output.WriteLine("Copying default stream into alternate stream.");
Copy(testFileDefaultStream, testFileAlternateStream);
Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Expand All @@ -361,6 +381,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));
_output.WriteLine($"Attributes for '{testFile2DefaultStream}': {File.GetAttributes(testFile2DefaultStream)}");
_output.WriteLine($"Attributes for '{testFileAlternateStream}': {File.GetAttributes(testFileAlternateStream)}");
_output.WriteLine("Overwriting alternate stream.");
Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;
using Xunit.Abstractions;

namespace System.IO.Tests
{
Expand All @@ -16,6 +17,11 @@ protected override void Copy(string source, string dest)

public class FileInfo_CopyTo_str_b : File_Copy_str_str_b
{
public FileInfo_CopyTo_str_b(ITestOutputHelper output)
: base(output)
{
}

protected override void Copy(string source, string dest)
{
new FileInfo(source).CopyTo(dest, false);
Expand Down
Loading