Changing directory and file permission on linux with C# 5.0 #45641
-
Is there a library that can change file or directory permissions on linux. I have a class that set's or remove's the permissions from directory and files based on user permission. I'm getting the new warning CA1416. So before I go through and put the IsWindows flag on everything I want to see if there a linux way so I can update my class to work on both OS's. Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The filesystem permissions model in Linux is far too different from Windows to make a general-purpose solution unless your needs are extremely limited. (Like all you want is to toggle a file as read-only.) As far as I'm aware, Mono.Posix.NETStandard is still the way to go if you need access to stuff like that on Linux. You can use one of the child classes of (See also: #19958) (Also I'm unsure if those documentation links are still being updated. They may not be entirely up-to-date.) |
Beta Was this translation helpful? Give feedback.
-
.NET 7 has added https://learn.microsoft.com/en-us/dotnet/api/system.io.file.setunixfilemode?view=net-8.0 (won't work on Windows though) |
Beta Was this translation helpful? Give feedback.
The filesystem permissions model in Linux is far too different from Windows to make a general-purpose solution unless your needs are extremely limited. (Like all you want is to toggle a file as read-only.)
As far as I'm aware, Mono.Posix.NETStandard is still the way to go if you need access to stuff like that on Linux. You can use one of the child classes of
Mono.Unix.UnixFileSystemInfo
to manipulate the permissions of a file, or you can just callchmod
directly.(See also: #19958)
(Also I'm unsure if those documentation links are still being updated. They may not be entirely up-to-date.)