Cross-platform representation of permissions on a file.
The readonly and setReadonly are the only methods available across all platforms.
Platform-specific functionality is available through the inner field.
inner: switch (builtin.os.tag) {
.windows => PermissionsWindows,
else => PermissionsUnix,
}You may use the inner field to use platform-specific functionality
pub fn readOnly(self: Self) boolReturns true if permissions represent an unwritable file.
On Unix, true is returned only if no class has write permissions.
self: Selfpub fn readOnly(self: Self) bool {
return self.inner.readOnly();
}pub fn setReadOnly(self: *Self, read_only: bool) voidSets whether write permissions are provided.
On Unix, this affects all classes. If this is undesired, use unixSet.
This method DOES NOT set permissions on the filesystem: use File.setPermissions(permissions)
self: *Selfread_only: boolpub fn setReadOnly(self: *Self, read_only: bool) void {
self.inner.setReadOnly(read_only);
}pub const Permissions = struct {
/// You may use the `inner` field to use platform-specific functionality
inner: switch (builtin.os.tag) {
.windows => PermissionsWindows,
else => PermissionsUnix,
},
const Self = @This();
/// Returns `true` if permissions represent an unwritable file.
/// On Unix, `true` is returned only if no class has write permissions.
pub fn readOnly(self: Self) bool {
return self.inner.readOnly();
}
/// Sets whether write permissions are provided.
/// On Unix, this affects *all* classes. If this is undesired, use `unixSet`.
/// This method *DOES NOT* set permissions on the filesystem: use `File.setPermissions(permissions)`
pub fn setReadOnly(self: *Self, read_only: bool) void {
self.inner.setReadOnly(read_only);
}
}