Event ‣ rename - chung-leong/zigar GitHub Wiki

Occurs when a system call is made to rename or move a file.

Usage

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

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

rename('/var/mushroom/kingdom/mario.txt', '/var/mushroom/kingdom/luigi.txt');
{
  parent: null,
  path: 'var/mushroom/kingdom/mario.txt',
  newParent: null,
  newPath: 'var/mushroom/kingdom/luigi.txt'
}

Event fields:

  • parent: object
    The parent directory, if the event is triggered by a call to renameat() 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.
  • newPath: string Path pointing to the file's new location.
  • newParent: object The new parent directory.

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