Skip to content

Commit

Permalink
fix: initialization of UnixFileMode (#662)
Browse files Browse the repository at this point in the history
* Fix initialization of `UnixFileMode`
* Add tests
  • Loading branch information
vbreuss authored Nov 8, 2024
1 parent 76ae620 commit 0837b0b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public IFileSystemExtensibility Extensibility

#if FEATURE_FILESYSTEM_UNIXFILEMODE
/// <inheritdoc cref="IStorageContainer.UnixFileMode" />
public UnixFileMode UnixFileMode { get; set; } = (UnixFileMode)(-1);
public UnixFileMode UnixFileMode { get; set; } = UnixFileMode.OtherRead |
UnixFileMode.GroupRead |
UnixFileMode.UserWrite |
UnixFileMode.UserRead;
#endif

/// <inheritdoc cref="IStorageContainer.AppendBytes(byte[])" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ public abstract partial class UnixFileModeTests<TFileSystem>
: FileSystemTestBase<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableTheory]
[AutoData]
public void GetUnixFileMode_ShouldBeInitializedCorrectly(
string path)
{
Skip.If(Test.RunsOnWindows);

FileSystem.File.WriteAllText(path, "");
UnixFileMode expected = UnixFileMode.OtherRead |
UnixFileMode.GroupRead |
UnixFileMode.UserWrite |
UnixFileMode.UserRead;

#pragma warning disable CA1416
UnixFileMode result = FileSystem.File.GetUnixFileMode(path);
#pragma warning restore CA1416

result.Should().Be(expected);
}

[SkippableTheory]
[AutoData]
public void GetUnixFileMode_ShouldThrowPlatformNotSupportedException_OnWindows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ public void UnixFileMode_SetterShouldThrowPlatformNotSupportedException_OnWindow

[SkippableTheory]
[AutoData]
public void UnixFileMode_ShouldBeInitializedToMinusOne(
public void UnixFileMode_ShouldBeInitializedCorrectly(
string path)
{
Skip.IfNot(Test.RunsOnWindows);
Skip.If(Test.RunsOnWindows);

UnixFileMode expected = (UnixFileMode)(-1);
UnixFileMode expected = UnixFileMode.OtherRead |
UnixFileMode.GroupRead |
UnixFileMode.UserWrite |
UnixFileMode.UserRead;
FileSystem.File.WriteAllText(path, "some content");
IFileInfo fileSystemInfo = FileSystem.FileInfo.New(path);

Expand Down

0 comments on commit 0837b0b

Please sign in to comment.