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 FileAttributes.None #89130

Merged
merged 2 commits into from
Aug 2, 2023
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 @@ -11,6 +11,7 @@ public static class FileAttributesTests
[Fact]
public static void ValueTest()
{
Assert.Equal(0x0000, (int)FileAttributes.None);
Assert.Equal(0x0001, (int)FileAttributes.ReadOnly);
Assert.Equal(0x0002, (int)FileAttributes.Hidden);
Assert.Equal(0x0004, (int)FileAttributes.System);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override FileAttributes GetAttributes(string path)
using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.Read);
return File.GetAttributes(fileHandle);
}

protected override void SetAttributes(string path, FileAttributes attributes)
{
using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.ReadWrite);
Expand All @@ -33,7 +33,7 @@ protected override void SetAttributes(string path, FileAttributes attributes)
public void NullArgumentValidation()
{
Assert.Throws<ArgumentNullException>("fileHandle", static () => File.GetAttributes(default(SafeFileHandle)!));
Assert.Throws<ArgumentNullException>("fileHandle", static () => File.SetAttributes(default(SafeFileHandle)!, (FileAttributes)0));
Assert.Throws<ArgumentNullException>("fileHandle", static () => File.SetAttributes(default(SafeFileHandle)!, FileAttributes.None));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public bool MoveNext()
}
}

if (!isSpecialDirectory && _options.AttributesToSkip != 0)
if (!isSpecialDirectory && _options.AttributesToSkip != FileAttributes.None)
{
// entry.IsHidden and entry.IsReadOnly will hit the disk if the caches had not been
// initialized yet and we could not soft-retrieve the attributes in Initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace System.IO
[Flags]
public enum FileAttributes
{
None = 0x0000,
ReadOnly = 0x0001,
Hidden = 0x0002,
System = 0x0004,
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9746,6 +9746,7 @@ public enum FileAccess
[System.FlagsAttribute]
public enum FileAttributes
{
None = 0,
ReadOnly = 1,
Hidden = 2,
System = 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public void ConvertFileAttributes(bool useGenericVariant)
options);
Assert.Equal(@"""directory, compressed, integrity_stream""", json);

json = JsonSerializer.Serialize(FileAttributes.Compressed & FileAttributes.Device, options);
Assert.Equal(@"0", json);
json = JsonSerializer.Serialize((FileAttributes)(-1), options);
Assert.Equal(@"-1", json);
Comment on lines +189 to +190
Copy link
Contributor Author

@meziantou meziantou Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous test was validating that an unknown value is serialized as a number.

FileAttributes.Compressed & FileAttributes.Device is now None. So, the test fails on net8 but succeeds on net462. I replaced the value with an unknown value (-1).


json = JsonSerializer.Serialize(FileAttributes.Directory & FileAttributes.Compressed | FileAttributes.IntegrityStream, options);
Assert.Equal(@"""integrity_stream""", json);
Expand Down
Loading