src/fusion/filepermissions

  • Convenience functions to convert Unix like file permissions to and from set[FilePermission].

Procs

proc chmod(path: string; permissions: Natural) {.inline, ...raises: [OSError],
    tags: [ReadDirEffect, WriteDirEffect].}

Convenience proc for os.setFilePermissions("file.ext", filepermissions.toFilePermissions(0o666)) to change file permissions using Unix like octal file permission.

See also:

func fromFilePermissions(perm: set[FilePermission]): uint {....raises: [], tags: [].}

Convenience func to convert set[FilePermission] to Unix like file permission.

See also:

Example:

import os
doAssert fromFilePermissions({fpUserExec, fpUserRead, fpUserWrite}) == 0o700
doAssert fromFilePermissions({fpGroupExec, fpGroupRead, fpGroupWrite}) == 0o070
doAssert fromFilePermissions({fpOthersExec, fpOthersRead, fpOthersWrite}) == 0o007
doAssert fromFilePermissions({fpUserWrite, fpUserRead, fpGroupRead, fpOthersRead}) == 0o644
doAssert fromFilePermissions({fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}) == 0o777
doAssert fromFilePermissions({}) == 0o000
static: doAssert 0o777.toFilePermissions.fromFilePermissions == 0o777
func toFilePermissions(perm: Natural): set[FilePermission] {....raises: [],
    tags: [].}

Convenience func to convert Unix like file permission to set[FilePermission].

See also:

Example:

import os
doAssert toFilePermissions(0o700) == {fpUserExec, fpUserRead, fpUserWrite}
doAssert toFilePermissions(0o070) == {fpGroupExec, fpGroupRead, fpGroupWrite}
doAssert toFilePermissions(0o007) == {fpOthersExec, fpOthersRead, fpOthersWrite}
doAssert toFilePermissions(0o644) == {fpUserWrite, fpUserRead, fpGroupRead, fpOthersRead}
doAssert toFilePermissions(0o777) == {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}
doAssert toFilePermissions(0o000) == {}