nodefs

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package nodefs ports the fs contracts Pi relies on: the directory order of fs.readdirSync and fs.existsSync.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Access

func Access(name string) bool

Access is fs.accessSync(path, F_OK) and reports whether it succeeds. Unlike Exists it is the one existence check Node shares between platforms: on Unix both are access(2).

Ports packages/coding-agent/src/utils/shell.ts (the accessSync(path, F_OK) existence check of shellPathExists).

func EntryKind

func EntryKind(dir string, entry os.DirEntry) (isDir, isFile, ok bool)

EntryKind classifies a directory entry as Pi's directory collectors do: from the entry's own type, following the link with a stat only for a symlink. ok is false for a symlink whose target cannot be read, which those collectors skip. It does not stat a plain file or directory, so an entry whose name Node decoded still counts as the file or directory it was listed as.

func Exists

func Exists(name string) bool

Exists is fs.existsSync: Node asks access(2) for F_OK, which follows symbolic links and reads no metadata. Unlike os.Stat it allocates only the system call's copy of name: no FileInfo, and no PathError for a missing path.

func ParentDir

func ParentDir(dir string, clean bool) string

ParentDir is filepath.Dir of dir, and whether dir was already clean. clean reports that dir is a clean path, so the parent is dir sliced at its last separator, which costs no allocation; filepath.Dir cleans, and on Windows builds a new string for every path with a volume name. A caller passes the returned parent back with clean true. The first call of a walk passes clean false, as the caller's own path may be unclean.

func ReadDir

func ReadDir(name string) ([]os.DirEntry, error)

ReadDir returns the entries of the directory named by name in the order Node's fs.readdirSync returns them. libuv's scandir sorts them by name (strcmp) on Unix-like systems and returns them in the file system's own order on Windows, which on NTFS ignores case. On an error it returns the entries read before it, as os.ReadDir does. Like Node it hands out each name decoded as UTF-8, U+FFFD for each ill-formed subpart, so a path joined from such a name no longer names the file, as in Pi.

Types

type PathProbe

type PathProbe struct {
	// contains filtered or unexported fields
}

PathProbe asks fs.existsSync of paths below a directory without building a path string per probe: an ancestor walk probes the same few names at every level. The zero value is ready to use; one PathProbe serves one goroutine.

func (*PathProbe) Exists

func (p *PathProbe) Exists() bool

Exists is fs.existsSync of the probe's path.

func (*PathProbe) Is

func (p *PathProbe) Is(path string) bool

Is reports whether the probe's path is path.

func (*PathProbe) Set

func (p *PathProbe) Set(dir string, elems ...string) *PathProbe

Set makes the probe's path path.join(dir, elems...) for a clean dir and elements that are plain names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL