Function setPermissions [src]

Sets permissions according to the provided Permissions struct. This method is NOT available on WASI

Prototype

pub fn setPermissions(self: File, permissions: Permissions) SetPermissionsError!void

Parameters

self: Filepermissions: Permissions

Possible Errors

AccessDenied FChmodError
FileNotFound FChmodError
InputOutput FChmodError
PermissionDenied FChmodError
ReadOnlyFileSystem FChmodError
SymLinkLoop FChmodError
SystemResources FChmodError
Unexpected UnexpectedError

The Operating System returned an undocumented error code.

This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.

When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.

Source

pub fn setPermissions(self: File, permissions: Permissions) SetPermissionsError!void { switch (builtin.os.tag) { .windows => { var io_status_block: windows.IO_STATUS_BLOCK = undefined; var info = windows.FILE_BASIC_INFORMATION{ .CreationTime = 0, .LastAccessTime = 0, .LastWriteTime = 0, .ChangeTime = 0, .FileAttributes = permissions.inner.attributes, }; const rc = windows.ntdll.NtSetInformationFile( self.handle, &io_status_block, &info, @sizeOf(windows.FILE_BASIC_INFORMATION), .FileBasicInformation, ); switch (rc) { .SUCCESS => return, .INVALID_HANDLE => unreachable, .ACCESS_DENIED => return error.AccessDenied, else => return windows.unexpectedStatus(rc), } }, .wasi => @compileError("Unsupported OS"), // Wasi filesystem does not *yet* support chmod else => { try self.chmod(permissions.inner.mode); }, } }