fs

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultArchiveOneFileSystem bool

DefaultArchiveOneFileSystem is the default for OneFileSystem on archive scans.

View Source
var DefaultOneFileSystem bool

DefaultOneFileSystem is the default for OneFileSystem on new LocalFS instances (src+dst scans).

View Source
var ErrNotBtrfs = fmt.Errorf("not a btrfs filesystem")

BtrfsWalk performs a recursive directory walk using BTRFS_IOC_TREE_SEARCH to batch-read directory entries and inode metadata. If a subdirectory is on a different device (submount), it falls back to standard stat-based walk for that subtree. Returns ErrNotBtrfs if the root path is not on BTRFS.

Functions

func IsBtrfs added in v2.1.0

func IsBtrfs(path string) bool

IsBtrfs returns true if the given path is on a BTRFS filesystem, using a cached mount table with longest-prefix matching.

Types

type DirEntry

type DirEntry struct {
	// RelativePath is the path relative to the walk root.
	RelativePath string
	// Size is the file size in bytes (0 for directories).
	Size int64
	// ModTime is the modification time as a Unix timestamp.
	ModTime int64
	// IsDir is true for directory entries.
	IsDir bool
}

DirEntry represents a single file or directory discovered during Walk.

func BtrfsWalk added in v2.1.0

func BtrfsWalk(dirPath string, excludedNames map[string]struct{}, counter *int32) ([]DirEntry, error)

type FileInfo

type FileInfo struct {
	Name    string
	Size    int64
	Mode    fs.FileMode
	ModTime time.Time
	IsDir   bool
}

FileInfo holds the subset of os.FileInfo fields we need.

type FileSystem

type FileSystem interface {
	// Walk recursively walks dirPath, returning all regular files.
	// excludedNames contains base names to skip (files and directories).
	// counter, if non-nil, is incremented atomically for each regular file found.
	Walk(dirPath string, excludedNames map[string]struct{}, counter *int32) ([]DirEntry, error)

	// Lstat returns file info without following symlinks.
	Lstat(path string) (FileInfo, error)

	// Stat returns file info, following symlinks.
	Stat(path string) (FileInfo, error)

	// ReadFile reads the entire file.
	ReadFile(path string) ([]byte, error)

	// ReadAt reads len(buf) bytes starting at offset.
	ReadAt(path string, buf []byte, offset int64) (int, error)

	// Rename moves/renames a file.
	Rename(oldPath, newPath string) error

	// Chtimes changes the access and modification times of the named file.
	Chtimes(path string, atime, mtime time.Time) error

	// MkdirAll creates a directory path and all parents that do not yet exist.
	MkdirAll(path string) error

	// IsReadableDirectory returns true if path is an existing, readable directory.
	IsReadableDirectory(path string) bool

	// Close releases any resources held by the filesystem (e.g. SSH connections).
	Close() error
}

FileSystem abstracts file system operations so that callers can work with local directories, SFTP mounts, or remote agents interchangeably.

type LocalFS

type LocalFS struct {
	OneFileSystem bool // if true, skip directories on different filesystems
	// contains filtered or unexported fields
}

LocalFS implements FileSystem using standard os.* calls.

func NewLocalFS

func NewLocalFS() *LocalFS

NewLocalFS returns a new LocalFS.

func NewLocalFSForArchive

func NewLocalFSForArchive() *LocalFS

NewLocalFSForArchive returns a LocalFS configured for archive scanning.

func (*LocalFS) Chtimes

func (l *LocalFS) Chtimes(path string, atime, mtime time.Time) error

func (*LocalFS) Close

func (l *LocalFS) Close() error

func (*LocalFS) IsReadableDirectory

func (l *LocalFS) IsReadableDirectory(path string) bool

func (*LocalFS) Lstat

func (l *LocalFS) Lstat(path string) (FileInfo, error)

func (*LocalFS) MkdirAll

func (l *LocalFS) MkdirAll(path string) error

func (*LocalFS) ReadAt

func (l *LocalFS) ReadAt(path string, buf []byte, offset int64) (int, error)

func (*LocalFS) ReadFile

func (l *LocalFS) ReadFile(path string) ([]byte, error)

func (*LocalFS) Rename

func (l *LocalFS) Rename(oldPath, newPath string) error

func (*LocalFS) Stat

func (l *LocalFS) Stat(path string) (FileInfo, error)

func (*LocalFS) Walk

func (l *LocalFS) Walk(dirPath string, excludedNames map[string]struct{}, counter *int32) ([]DirEntry, error)

type SFTPFS

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

SFTPFS implements FileSystem over an SFTP connection.

func NewSFTPFS

func NewSFTPFS(client *sftp.Client) *SFTPFS

NewSFTPFS wraps an existing sftp.Client in a FileSystem.

func (*SFTPFS) Chtimes

func (s *SFTPFS) Chtimes(p string, atime, mtime time.Time) error

func (*SFTPFS) Close

func (s *SFTPFS) Close() error

func (*SFTPFS) IsReadableDirectory

func (s *SFTPFS) IsReadableDirectory(p string) bool

func (*SFTPFS) Lstat

func (s *SFTPFS) Lstat(p string) (FileInfo, error)

func (*SFTPFS) MkdirAll

func (s *SFTPFS) MkdirAll(p string) error

func (*SFTPFS) ReadAt

func (s *SFTPFS) ReadAt(p string, buf []byte, offset int64) (int, error)

func (*SFTPFS) ReadFile

func (s *SFTPFS) ReadFile(p string) ([]byte, error)

func (*SFTPFS) Rename

func (s *SFTPFS) Rename(oldPath, newPath string) error

func (*SFTPFS) Stat

func (s *SFTPFS) Stat(p string) (FileInfo, error)

func (*SFTPFS) Walk

func (s *SFTPFS) Walk(dirPath string, excludedNames map[string]struct{}, counter *int32) ([]DirEntry, error)

Jump to

Keyboard shortcuts

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