Event ‣ readlink - chung-leong/zigar GitHub Wiki
Occurs when a system call is made to read a symbolic link.
Usage
const std = @import("std");
pub fn readlink(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
var buffer: [std.fs.max_path_bytes]u8 = undefined;
const target = try std.posix.readlink(path, &buffer);
return try allocator.dupe(u8, target);
}
import { __zigar, readlink } from './event-readlink-example-1.zig';
const { on } = __zigar;
on('readlink', (evt) => {
console.log(evt);
return '/var/mushroom/kingdom/luigi.txt';
})
const result = readlink('/var/mushroom/kingdom/mario.txt');
console.log(result.string);
{ parent: null, path: 'var/mushroom/kingdom/mario.txt' }
/var/mushroom/kingdom/luigi.txt
Event fields:
parent:object
The parent directory, if the event is triggered by a call to readlinkat() or std.fs.Dir.readLink(). It'snullwhen 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:
string|boolean|undefined
The path to the symlink's target if the operation succeeds. 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.