vcom/internal/vfs/fileinfo.go
vrubelroman 2db51e9385 feat(vfs): define the vfs.FS contract, sentinels, PathOps and ReadOnly wrapper (2.0)
Types and interfaces from design §2.1: FS, File, FileInfo, Caps, VolumeID,
RenameMode, CreateMode, PathOps (posix and native), Location.Same, the
optional Trasher/BirthTimer/Execer interfaces and ReadOnly(fs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:21:41 +03:00

36 lines
1.2 KiB
Go

package vfs
import (
"io/fs"
"time"
)
// FileInfo describes one directory entry with lstat semantics.
type FileInfo struct {
Name string
Size int64
Mode fs.FileMode // as from Lstat: ModeSymlink, ModeDir, ModeNamedPipe, ...
ModTime time.Time
// Target is the Stat of a symlink's target; nil if the link is broken or
// the target was not resolved. LinkErr says why it is nil.
Target *FileInfo
LinkErr error
}
// IsDir reports whether the entry itself is a directory (not a link to one).
func (fi FileInfo) IsDir() bool { return fi.Mode.IsDir() }
// IsSymlink reports whether the entry is a symbolic link.
func (fi FileInfo) IsSymlink() bool { return fi.Mode&fs.ModeSymlink != 0 }
// NavigableDir reports whether a panel can enter the entry: a directory or a
// symlink whose target is a directory (U-P1-2).
func (fi FileInfo) NavigableDir() bool {
return fi.IsDir() || (fi.IsSymlink() && fi.Target != nil && fi.Target.IsDir())
}
// IsRegularLike reports whether the entry is a regular file or a symlink to
// one. FIFOs, devices and sockets are not.
func (fi FileInfo) IsRegularLike() bool {
return fi.Mode.IsRegular() || (fi.IsSymlink() && fi.Target != nil && fi.Target.Mode.IsRegular())
}