我在用mono开发crossplatform应用程序。我想检查运行应用程序的用户的rw访问权限。在NT上,我可以使用.getaccesscontrol方法(在mono-throws平台上,不支持异常),但是如何处理*nix和macos?有没有crossplatfrom的解决方案?

最佳答案

mono.unix有特定于unix的实现:

var ufi = new UnixFileInfo("/tmp/test.cpp");
ufi.CanAccess(AccessModes.F_OK); // is a file/directory
ufi.CanAccess(AccessModes.R_OK); // accessible for reading
ufi.CanAccess(AccessModes.W_OK); // accessible for writing
ufi.CanAccess(AccessModes.X_OK); // accessible for executing
FileSpecialAttributes sa = ufi.FileSpecialAttributes; //setuid, setgid and sticky bits
FileAccessPermissions fa = ufi.FileAccessPermissions;

FileAccessPermissions定义为:
[Flags ()]
public enum FileAccessPermissions {
    UserReadWriteExecute,
    UserRead,
    UserWrite,
    UserExecute,
    GroupReadWriteExecute,
    GroupRead,
    GroupWrite,
    GroupExecute,
    OtherReadWriteExecute,
    OtherRead,
    OtherWrite,
    OtherExecute,
    DefaultPermissions,
    AllPermissions
}

09-04 19:39