Event ‣ unlink - chung-leong/zigar GitHub Wiki

Occurs when a system call is made to remove a file.

Usage

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

on('unlink', (evt) => {
  console.log(evt);
  return true;
})

unlink('/var/mushroom/kingdom/mario.txt');
{ parent: null, path: 'var/mushroom/kingdom/mario.txt' }

Event fields:

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

Return value:

boolean|undefined
true if the operation succeeds or false otherwise. 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