Why fs.File doesn't have a method to generate full path

The function you’re looking for is std.os.getFdPath. To call it for a File, you’d pass it file.handle; to call it for a Dir, you’d pass it dir.fd. Calling it with the result of std.fs.cwd() should be done with great care (on POSIX systems, std.fs.cwd() does not return a real fd, see here).

However, take note of its documentation:

/// This function is very host-specific and is not universally supported by all hosts.
/// For example, while it generally works on Linux, macOS, FreeBSD or Windows, it is
/// unsupported on WASI.
///
/// Calling this function is usually a bug.

Related issue that pertains to getFdPath and realpath generally:

1 Like