Documentation
¶
Index ¶
- Variables
- func BreadthOrder(fs absfs.Filer, options *Options, path string, fn filepath.WalkFunc) error
- func Copy(src, dst absfs.FileSystem, srcPath, dstPath string, opts *CopyOptions) error
- func CopyToFS(src, dst absfs.FileSystem, path string) error
- func Equal(fs1 absfs.FileSystem, path1 string, fs2 absfs.FileSystem, path2 string) (bool, error)
- func Exists(fs absfs.Filer, path string) bool
- func FastWalk(filer absfs.Filer, root string, fn FastWalkFunc) error
- func FastWalkWithConfig(filer absfs.Filer, root string, config *FastWalkConfig, fn FastWalkFunc) error
- func KeyOrder(fs absfs.Filer, options *Options, path string, fn filepath.WalkFunc) error
- func PostOrder(fs absfs.Filer, options *Options, path string, fn filepath.WalkFunc) error
- func PreOrder(fs absfs.Filer, options *Options, path string, fn filepath.WalkFunc) error
- func Size(fs absfs.Filer, path string) (int64, error)
- func Walk(filer absfs.Filer, path string, fn filepath.WalkFunc) error
- func WalkWithOptions(filer absfs.Filer, options *Options, path string, fn filepath.WalkFunc) error
- type CopyOptions
- type CountResult
- type FastWalkConfig
- type FastWalkFunc
- type Options
- type ParallelCopyOptions
- type ParallelCopyStats
- type SortFunc
- type Traversal
Constants ¶
This section is empty.
Variables ¶
var TraverseLink = errors.New("traverse symlink, assuming target is a directory")
TraverseLink is a sentinel error that can be returned from FastWalkFunc to indicate that a symlink should be traversed as a directory. The caller is responsible for cycle detection.
Functions ¶
func BreadthOrder ¶
func Copy ¶
func Copy(src, dst absfs.FileSystem, srcPath, dstPath string, opts *CopyOptions) error
Copy copies files and directories from src filesystem to dst filesystem. It recursively copies the entire directory tree starting at srcPath to dstPath. If opts.Parallel is true, uses concurrent copying for better performance on thread-safe filesystems.
func CopyToFS ¶
func CopyToFS(src, dst absfs.FileSystem, path string) error
CopyToFS is a convenience wrapper that copies from src to dst filesystem using the same path for both source and destination.
func Equal ¶
func Equal(fs1 absfs.FileSystem, path1 string, fs2 absfs.FileSystem, path2 string) (bool, error)
Equal compares two files or directory trees for identical content. For files, it compares the content byte-by-byte. For directories, it recursively compares all files and subdirectories.
func FastWalk ¶
func FastWalk(filer absfs.Filer, root string, fn FastWalkFunc) error
FastWalk walks the file tree rooted at root concurrently, calling fn for each file. It is significantly faster than Walk because:
- Runs multiple goroutines concurrently to traverse directories in parallel
- Avoids unnecessary stat calls by using DirEntry type information
When the underlying filesystem is osfs, the platform-optimized ReadDir implementation is used automatically (e.g., getdents with d_type on Linux).
The fn must be safe for concurrent use as it may be called from multiple goroutines. If fn returns filepath.SkipDir, the directory is skipped. If fn returns TraverseLink for a symlink, it will be traversed as a directory.
func FastWalkWithConfig ¶
func FastWalkWithConfig(filer absfs.Filer, root string, config *FastWalkConfig, fn FastWalkFunc) error
FastWalkWithConfig is like FastWalk but accepts a configuration.
Types ¶
type CopyOptions ¶
type CopyOptions struct {
// Parallel enables concurrent copying for thread-safe filesystems
Parallel bool
// PreserveMode preserves file permissions
PreserveMode bool
// PreserveTimes preserves modification times
PreserveTimes bool
// Filter is called for each file/directory to determine if it should be copied
// Return false to skip the item
Filter func(path string, info os.FileInfo) bool
// OnError is called when an error occurs during copy
// Return nil to continue, or an error to stop
OnError func(path string, err error) error
}
CopyOptions configures the behavior of copy operations.
type CountResult ¶
CountResult contains the results of a Count operation.
func Count ¶
func Count(fs absfs.Filer, path string) (CountResult, error)
Count counts the number of files and directories under a path. The path itself is included in the count.
func (CountResult) Total ¶
func (c CountResult) Total() int64
Total returns the total number of files and directories.
type FastWalkConfig ¶
type FastWalkConfig struct {
// NumWorkers sets the number of concurrent workers.
// If 0 or negative, defaults to max(4, runtime.NumCPU()).
NumWorkers int
// FollowSymlinks determines whether symlinks should be followed.
// When true, symlinks to directories will be traversed.
// The caller must handle potential cycles.
FollowSymlinks bool
}
FastWalkConfig holds configuration options for FastWalk.
type FastWalkFunc ¶
FastWalkFunc is the callback function type for FastWalk. It receives fs.DirEntry instead of os.FileInfo for better performance (avoids stat calls when only type information is needed).
type ParallelCopyOptions ¶
type ParallelCopyOptions struct {
// NumWorkers sets the number of concurrent copy workers.
// If 0 or negative, defaults to max(4, runtime.NumCPU()).
NumWorkers int
// BufferSize sets the size of the copy buffer per worker.
// If 0, defaults to 32KB.
BufferSize int
// PreserveMode preserves file permissions.
PreserveMode bool
// PreserveTimes preserves modification times.
PreserveTimes bool
// Filter is called for each file/directory to determine if it should be copied.
// Return false to skip the item. Must be safe for concurrent use.
Filter func(path string, info os.FileInfo) bool
// OnError is called when an error occurs during copy.
// Return nil to continue, or an error to stop. Must be safe for concurrent use.
OnError func(path string, err error) error
// OnProgress is called after each file is copied with the number of bytes copied.
// Must be safe for concurrent use.
OnProgress func(path string, bytesWritten int64)
}
ParallelCopyOptions configures the behavior of parallel copy operations.
type ParallelCopyStats ¶
ParallelCopyStats contains statistics from a parallel copy operation.
func ParallelCopy ¶
func ParallelCopy(src, dst absfs.FileSystem, srcPath, dstPath string, opts *ParallelCopyOptions) (*ParallelCopyStats, error)
ParallelCopy copies files and directories from src to dst using concurrent workers. It is significantly faster than Copy for large directory trees with many files.