Skip to content

setMode

Sets permissions for a file or directory.

Example

ts
import { 
SF
} from "@duplojs/server-utils";
const
result
= await
SF
.
setMode
("/tmp/file.txt", 0o644);
// result: E.Ok | SF.FileSystemLeft await
SF
.
setMode
("/tmp/file.txt", {
user
: {
read
: true,
write
: true,
}, });

Syntax

typescript
function setMode(
  path: string | URL,
  mode: ModeObject | number
): Promise<FileSystemLeft | E.Ok>

ModeObject

typescript
interface Permissions {
  read?: boolean;
  write?: boolean;
  exec?: boolean;
}

interface ModeObject {
  user?: Permissions;
  group?: Permissions;
  other?: Permissions;
  setUserId?: boolean;
  setGroupId?: boolean;
  sticky?: boolean;
}

Parameters

  • path : target path.
  • mode : numeric mode (e.g., 0o644) or permissions object.

Return value

  • E.Ok : if the operation succeeds.
  • FileSystemLeft : if the operation fails.

Notes

  • Object-form permissions are converted to numeric mode.

See also

  • setOwner - Sets the owner of a file or directory.

Released under the MIT license.