dirent

package
v0.1.4321 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dirent decides whether an entry a reader lists is a folder to go into, links included.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each(dir string, f func(name string, s Stat) bool) (ok bool)

Each gives f each entry of dir as Stats has it, in the order the system lists them, with nothing made for an entry: name is valid only during the call, and f copies what it keeps of it. f returning false stops the listing. ok is false where Stats' is: the system has no such listing, or the folder or an entry couldn't be read (some entries may have been given f by then).

func Forget

func Forget()

Forget lets go of every listing kept for the next Stats, and the room kept for them: once the session folders go unread, the listings and their names were held for the life of the process (~4 MB for a real history). A listing given back later is kept again.

func IsFolder

func IsFolder(dir string, e fs.DirEntry) bool

IsFolder is whether e, an entry listed in dir, is a folder to read into: a folder of its own, or a link that leads to one. os.ReadDir reports a symlink as ModeSymlink and, on Windows, a junction as ModeIrregular (Go 1.23 and later), and neither as IsDir, so a reader that goes into only IsDir() entries, or IsDir() and ModeSymlink ones, walks past a folder kept on another drive with a junction left where it was (#2268). Such an entry is followed with os.Stat. A link to a file, a broken link and anything else irregular are no folder.

It follows only the entry it is asked about. A reader that recurses on it must keep its own record of the folders it has been in.

func Mark

func Mark() int

Mark is the point a WatchSince waits from: every change made before it.

func Watch

func Watch(dir string)

Watch has dir and everything under it watched for changes, where the system can, and waits until every change made before the call is heard: a reader calls it before each read of dir's folders, and Stats of a folder in it then skips listing one that hasn't changed. A Stats with no Watch of its root in the last trustFor reads its folder.

func WatchSince

func WatchSince(dir string, mark int)

WatchSince is Watch, waiting only until every change made before mark is heard: a probe begun after mark, its own or another's, vouches for them. A Sessions poll watches each Claude Code and Codex folder in turn, and each Watch wrote, waited on and removed a probe of its own, ~1/6 of the poll's CPU (#2278); the poll marks once, and its first probe does for every folder after.

Types

type Entry added in v0.1.1664

type Entry struct {
	Name string
	Stat
}

Entry is one entry of a Listing.

type Listing added in v0.1.1664

type Listing []Entry

Listing is a folder's entries in name order. It is a slice, not a map: every 15 s Sessions poll lists every Codex day folder and Claude Code project again, and a map of each folder's entries was ~90 MB of the 2.3 GB eight polls allocated.

func Stats added in v0.1.1651

func Stats(dir string) (Listing, bool)

Stats is each entry of dir in name order, as os.Lstat gives it, read in a few calls for the whole folder where the system has them (getattrlistbulk on macOS), rather than one per entry. ok is false where the system has none or the folder couldn't be read, and the caller asks after each entry itself.

A caller done reading the listing gives it back (Done) for the next.

func (Listing) Done added in v0.1.2132

func (l Listing) Done(dir string)

Done gives l, dir's listing, back for the next Stats of dir: whoever had it reads it no more. A Get of it before is only a copy of its entry.

func (Listing) Get added in v0.1.1664

func (l Listing) Get(name string) (Stat, bool)

Get is name's entry.

type Stat added in v0.1.1651

type Stat struct {
	Size int64
	Mod  int64
	Mode fs.FileMode
}

Stat is what a folder's listing says of one entry: its kind (Mode's type bits, 0 for a regular file), and a regular file's size and modification time, as os.Lstat gives them. Mod is unix nanoseconds, not a time.Time: what is kept of a history's listings is ~130k entries, and its 24 bytes made an entry 56 bytes where it is now 40 (#2278).

func (Stat) ModTime added in v0.1.3410

func (s Stat) ModTime() time.Time

ModTime is Mod as a time, as os.Lstat's ModTime has it.

Jump to

Keyboard shortcuts

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