Event ‣ mkdir - chung-leong/zigar GitHub Wiki

Occurs when a system call is made to create a directory.

Usage

const std = @import("std");
pub const mkdir = std.posix.mkdir;
import { __zigar, mkdir } from './event-mkdir-example-1.zig';
const { on } = __zigar;

on('mkdir', (evt) => {
  console.log(evt);
  return new Map();
})

mkdir('/var/mushroom/kingdom', 0o666);
{ parent: null, path: 'var/mushroom/kingdom' }
node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

Error: Path already exists
    at mkdir (<anonymous>:1340:26)
    at file:///home/rwiggum/examples/event-mkdir-example-1.js:9:1
    at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  number: 30
}

Event fields:

  • parent: object
    The parent directory, if the event is triggered by a call to mkdirat() or std.fs.Dir.makeDir(). It's null when an absolute path is used to reference the directory.
  • path: string
    Relative path to the directory. No leading slash even when an absolute path is used.

Return value:

boolean | Map | undefined
true if the operation succeeds or false otherwise. A Map indicates the directory already exists. undefined means the listener declined to handle the event, allowing the operation to be handled by the actual file system.

Note:

The callback function can be async, provided that it's never invoked in the main thread.


Events

⚠️ **GitHub.com Fallback** ⚠️