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

Refactor Chmod implementation to use UnixFileMode and remove Mono.Posix dependency #53

Merged

Conversation

jetersen
Copy link
Contributor

@jetersen jetersen commented Nov 8, 2024

Environment.IsPrivilegedProcess calls IsPrivilegedProcessCore which calls Interop.Sys.GetEUid() == 0 on unix

We could properly use the same method for Windows although we are not checking if we are administrator, it checks if the token is elevated:
https://github.com/dotnet/runtime/blob/60b84bb13e499e0866731dbe21973b92b7abed15/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs#L89-L115

The reason to remove this dependency is it carries around a libMonoPosixHelper.so/dylib/dll which is unnecessary for the functionality that we need. Which can be solved entirely in the BCL.

SetUnixFileMode was added in .NET 7

@@ -30,11 +30,10 @@ public void Should_Convert_Default_Permissions_To_Correct_File_Access_Permission
var result = chmod.ToFileAccessPermissions();

// Then
result.ShouldBe(FileAccessPermissions.DefaultPermissions);
Copy link
Contributor Author

@jetersen jetersen Nov 8, 2024

Choose a reason for hiding this comment

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

DefaultPermissions does not exist on UnixFileMode also not relevant to the test.

Copy link
Owner

@patriksvensson patriksvensson left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@patriksvensson patriksvensson merged commit 99e8399 into patriksvensson:main Nov 9, 2024
1 check passed
@jetersen jetersen deleted the remove/Mono.Posix.NETStandard branch November 10, 2024 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants