Documentation
¶
Index ¶
- Constants
- Variables
- func AppendFile(fsys FS, filename string, data []byte) error
- func Chmod(fsys FS, name string, mode FileMode) error
- func Chown(fsys FS, name string, uid, gid int) error
- func Chtimes(fsys FS, name string, atime time.Time, mtime time.Time) error
- func ContextFor(fsys FS) context.Context
- func CopyAll(fsys FS, src, dst string) error
- func CopyFS(srcFS FS, srcPath string, dstFS FS, dstPath string) error
- func CopyNewFS(srcFS FS, srcPath string, dstFS FS, dstPath string) error
- func DirExists(fsys FS, path string) (bool, error)
- func Equal(a, b FS) bool
- func Exists(fsys FS, path string) (bool, error)
- func FollowSymlinks(ctx context.Context) bool
- func GetXattr(ctx context.Context, fsys FS, name string, attr string) ([]byte, error)
- func IsDir(fsys FS, path string) (bool, error)
- func IsEmpty(fsys FS, path string) (bool, error)
- func IsReadOnly(ctx context.Context) bool
- func IsSymlink(mode FileMode) bool
- func ListXattrs(ctx context.Context, fsys FS, name string) ([]string, error)
- func Mkdir(fsys FS, name string, perm FileMode) error
- func MkdirAll(fsys FS, name string, perm FileMode) error
- func Op(ctx context.Context) string
- func ReadAt(f File, p []byte, off int64) (int, error)
- func Readlink(fsys FS, name string) (string, error)
- func Remove(fsys FS, name string) error
- func RemoveAll(fsys FS, name string) error
- func RemoveXattr(ctx context.Context, fsys FS, name string, attr string) error
- func Rename(fsys FS, oldname, newname string) error
- func ResolveTo[T FS](fsys FS, ctx context.Context, name string) (T, string, error)
- func SameFile(a, b File) bool
- func Seek(f File, offset int64, whence int) (int64, error)
- func SetXattr(ctx context.Context, fsys FS, name string, attr string, data []byte, flags int) error
- func Symlink(fsys FS, oldname, newname string) error
- func Sync(f File) error
- func TempDir(fsys FS, dir, prefix string) (name string, err error)
- func Truncate(fsys FS, name string, size int64) error
- func Watch(fsys FS, ctx context.Context, name string, exclude ...string) (<-chan Event, error)
- func WithFilepath(ctx context.Context, filepath string) context.Context
- func WithNoFollow(ctx context.Context) context.Context
- func WithOp(ctx context.Context, op string) context.Context
- func WithOrigin(ctx context.Context, fsys FS, name string, op string) context.Context
- func WithReadOnly(ctx context.Context) context.Context
- func Write(f File, data []byte) (int, error)
- func WriteAt(f File, data []byte, off int64) (n int, err error)
- func WriteFile(fsys FS, filename string, data []byte, perm FileMode) error
- type ChmodFS
- type ChownFS
- type ChtimesFS
- type CreateFS
- type DefaultFS
- func (f *DefaultFS) Chmod(name string, mode FileMode) error
- func (f *DefaultFS) Chown(name string, uid, gid int) error
- func (f *DefaultFS) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (f *DefaultFS) Create(name string) (File, error)
- func (f *DefaultFS) GetXattr(ctx context.Context, name string, attr string) ([]byte, error)
- func (f *DefaultFS) ListXattrs(ctx context.Context, name string) ([]string, error)
- func (f *DefaultFS) Lstat(name string) (FileInfo, error)
- func (f *DefaultFS) LstatContext(ctx context.Context, name string) (FileInfo, error)
- func (f *DefaultFS) Mkdir(name string, perm FileMode) error
- func (f *DefaultFS) MkdirAll(name string, perm FileMode) error
- func (f *DefaultFS) OpenContext(ctx context.Context, name string) (File, error)
- func (f *DefaultFS) OpenFile(name string, flag int, perm FileMode) (File, error)
- func (f *DefaultFS) ReadDirContext(ctx context.Context, name string) ([]DirEntry, error)
- func (f *DefaultFS) Readlink(name string) (string, error)
- func (f *DefaultFS) Remove(name string) error
- func (f *DefaultFS) RemoveAll(name string) error
- func (f *DefaultFS) RemoveXattr(ctx context.Context, name string, attr string) error
- func (f *DefaultFS) Rename(oldname, newname string) error
- func (f *DefaultFS) SetXattr(ctx context.Context, name string, attr string, data []byte, flags int) error
- func (f *DefaultFS) Stat(name string) (FileInfo, error)
- func (f *DefaultFS) StatContext(ctx context.Context, name string) (FileInfo, error)
- func (f *DefaultFS) Sub(dir string) (FS, error)
- func (f *DefaultFS) Symlink(oldname, newname string) error
- func (f *DefaultFS) Truncate(name string, size int64) error
- func (f *DefaultFS) Watch(ctx context.Context, name string, exclude ...string) (<-chan Event, error)
- func (f *DefaultFS) WriteFile(name string, data []byte, perm FileMode) error
- type DefaultFile
- type DirEntry
- type Event
- type FS
- type File
- type FileInfo
- type FileMode
- type GlobFS
- type ID
- type IdentityFile
- type MkdirAllFS
- type MkdirFS
- type Namer
- type OpenContextFS
- type OpenFileFS
- type PathError
- type ReadDirContextFS
- type ReadDirFS
- type ReadDirFile
- type ReadFileFS
- type ReadlinkFS
- type RemoveAllFS
- type RemoveFS
- type RenameFS
- type ResolveFS
- type StatContextFS
- type StatFS
- type SubFS
- type SubdirFS
- func (f *SubdirFS) Chmod(name string, mode FileMode) error
- func (f *SubdirFS) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (f *SubdirFS) Create(name string) (File, error)
- func (f *SubdirFS) GetXattr(ctx context.Context, name string, attr string) ([]byte, error)
- func (f *SubdirFS) ListXattrs(ctx context.Context, name string) ([]string, error)
- func (f *SubdirFS) Mkdir(name string, perm FileMode) error
- func (f *SubdirFS) Open(name string) (File, error)
- func (f *SubdirFS) OpenContext(ctx context.Context, name string) (File, error)
- func (f *SubdirFS) Readlink(name string) (string, error)
- func (f *SubdirFS) Remove(name string) error
- func (f *SubdirFS) RemoveXattr(ctx context.Context, name string, attr string) error
- func (f *SubdirFS) Rename(oldname string, newname string) error
- func (f *SubdirFS) SetXattr(ctx context.Context, name string, attr string, data []byte, flags int) error
- func (f *SubdirFS) Stat(name string) (FileInfo, error)
- func (f *SubdirFS) StatContext(ctx context.Context, name string) (FileInfo, error)
- func (f *SubdirFS) Sub(dir string) (FS, error)
- func (f *SubdirFS) Symlink(oldname string, newname string) error
- func (f *SubdirFS) Truncate(name string, size int64) error
- type SymlinkFS
- type SyncFile
- type TruncateFS
- type WalkDirFunc
- type WatchFS
- type WriteFileFS
- type XattrFS
Constants ¶
const ( ModeDir = iofs.ModeDir ModeAppend = iofs.ModeAppend ModeExclusive = iofs.ModeExclusive ModeTemporary = iofs.ModeTemporary ModeSymlink = iofs.ModeSymlink ModeDevice = iofs.ModeDevice ModeNamedPipe = iofs.ModeNamedPipe ModeSocket = iofs.ModeSocket ModeSetuid = iofs.ModeSetuid ModeSetgid = iofs.ModeSetgid ModeCharDevice = iofs.ModeCharDevice ModeSticky = iofs.ModeSticky ModeIrregular = iofs.ModeIrregular ModeType = iofs.ModeType ModePerm = iofs.ModePerm )
Variables ¶
var ( // NoFollowContextKey is the context key for the no-follow flag. NoFollowContextKey = &contextKey{"no-follow"} // OriginContextKey is the context key for the originating filesystem. OriginContextKey = &contextKey{"origin"} // FilepathContextKey is the context key for the fully qualified path relative to the origin. FilepathContextKey = &contextKey{"filepath"} // ReadOnlyContextKey is the context key for the read-only flag. ReadOnlyContextKey = &contextKey{"read-only"} OpContextKey = &contextKey{"op"} )
var ( // new errors ErrNotSupported = errors.New("operation not supported") ErrNotEmpty = errors.New("directory not empty") )
var ( ErrInvalid = iofs.ErrInvalid ErrPermission = iofs.ErrPermission ErrExist = iofs.ErrExist ErrNotExist = iofs.ErrNotExist ErrClosed = iofs.ErrClosed SkipAll = iofs.SkipAll SkipDir = iofs.SkipDir )
var ( FormatDirEntry = iofs.FormatDirEntry FormatFileInfo = iofs.FormatFileInfo Glob = iofs.Glob ReadFile = iofs.ReadFile ValidPath = iofs.ValidPath WalkDir = iofs.WalkDir FileInfoToDirEntry = iofs.FileInfoToDirEntry ReadDir = iofs.ReadDir )
Functions ¶
func AppendFile ¶
deprecated? this doesnt always work because Open does not support O_APPEND
func ContextFor ¶
func CopyAll ¶
CopyAll recursively copies the file, directory or symbolic link at src to dst. The destination must not exist. Symbolic links are not followed.
If the copy fails half way through, the destination might be left partially written.
func CopyNewFS ¶
CopyNewFS copies from srcFS/srcPath to dstFS/dstPath, overwriting files if src is newer.
func FollowSymlinks ¶
FollowSymlinks returns true if symlinks should be followed and is intended to be used on contexts passed to OpenContext, et al.
func IsReadOnly ¶
IsReadOnly returns true if the context is read-only.
func MkdirAll ¶
MkdirAll creates a directory and any necessary parents with the given permissions if supported.
func Op ¶
Op returns the operation for the given context. TODO: this and other origin stuff should be a struct in a single context value.
func ReadAt ¶
ReadAt reads len(p) bytes into p starting at offset off in the file f. If f does not support ReadAt or Seek, it reads and discards bytes until the offset.
func ResolveTo ¶
ResolveTo resolves the name to an FS extension type if possible. It uses ResolveFS if available, otherwise it falls back to SubFS.
func Watch ¶
- use context to cancel watch - if context is done, return a closed channel - name can end with /... for recursive watch - exclude can be a glob pattern
func WithFilepath ¶
WithFilepath returns a new context with the FilepathContextKey set to the given filepath unless there is already a filepath in the context.
func WithNoFollow ¶
WithNoFollow returns a new context with the NoFollowContextKey set to true.
func WithOrigin ¶
WithOrigin returns a new context with the OriginContextKey set to the given filesystem unless there is already an origin filesystem in the context.
func WithReadOnly ¶
WithReadOnly returns a new context with the ReadOnlyContextKey set to true.
Types ¶
type DefaultFS ¶
DefaultFS wraps an fs.FS and implements all extended filesystem interfaces (MkdirFS, RemoveFS, RenameFS, etc.) by delegating to the corresponding package-level functions.
This is useful when embedding a filesystem in a new struct that only needs to override specific methods. Normally, if you embed an fs.FS interface in a struct, type assertions for extended interfaces will fail even if the underlying filesystem implements them. By wrapping with DefaultFS first, the wrapper struct gains implementations of all extended interfaces that properly delegate to the wrapped filesystem.
Example:
type myFS struct {
*fs.DefaultFS
}
func (m *myFS) Open(name string) (fs.File, error) {
// custom Open implementation
}
// Create wrapper - Mkdir, Remove, etc. will reach originalFS
wrapped := &myFS{DefaultFS: fs.NewDefault(originalFS)}
func NewDefault ¶
NewDefault wraps an fs.FS with DefaultFS to enable interface passthrough.
func (*DefaultFS) ListXattrs ¶
func (*DefaultFS) LstatContext ¶
func (*DefaultFS) OpenContext ¶
func (*DefaultFS) ReadDirContext ¶
func (*DefaultFS) RemoveXattr ¶
func (*DefaultFS) StatContext ¶
type DefaultFile ¶
DefaultFile wraps an fs.File and implements extended file interfaces (io.Writer, io.ReaderAt, io.WriterAt, io.Seeker, SyncFile) by delegating to the corresponding package-level functions.
Similar to DefaultFS, this allows embedding a file in a new struct while preserving access to the wrapped file's capabilities through type assertions.
func (DefaultFile) Sync ¶
func (f DefaultFile) Sync() error
type FS ¶
func Origin ¶
Origin returns the origin filesystem and filepath for the given context. The filepath may be empty but as long as there is an origin it will return true.
func Resolve ¶
Resolve resolves to the FS directly containing the name returning that resolved FS and the relative name for that FS. It uses ResolveFS if available, otherwise it falls back to SubFS. If unable to resolve, it returns the original FS and the original name, but it can also return a PathError if .
func Sub ¶
Sub returns an FS corresponding to the subtree rooted at fsys's dir.
If dir is ".", Sub returns fsys unchanged. Otherwise, if fs implements SubFS, Sub returns fsys.Sub(dir). Otherwise, Sub returns a new FS implementation sub that, in effect, implements sub.Open(name) as fsys.Open(path.Join(dir, name)). The implementation also translates calls to ReadDir, ReadFile, and Glob appropriately.
Note that Sub(os.DirFS("/"), "prefix") is equivalent to os.DirFS("/prefix") and that neither of them guarantees to avoid operating system accesses outside "/prefix", because the implementation of os.DirFS does not check for symbolic links inside "/prefix" that point to other directories. That is, os.DirFS is not a general substitute for a chroot-style security mechanism, and Sub does not change that fact.
type File ¶
func OpenContext ¶
OpenContext is a helper that opens a file with the given context and name falling back to Open if context is not supported. TODO: change to OpenContext(FS, Context, string)
type FileInfo ¶
func LstatContext ¶
TODO: change to StatContext(FS, Context, string)
type IdentityFile ¶
type OpenContextFS ¶
type OpenFileFS ¶
type ReadDirContextFS ¶
type ReadDirFile ¶
type ReadDirFile = iofs.ReadDirFile
type ReadFileFS ¶
type ReadFileFS = iofs.ReadFileFS
type RemoveAllFS ¶
type StatContextFS ¶
type SubdirFS ¶
func (*SubdirFS) ListXattrs ¶
func (*SubdirFS) OpenContext ¶
func (*SubdirFS) RemoveXattr ¶
func (*SubdirFS) StatContext ¶
type WalkDirFunc ¶
type WalkDirFunc = iofs.WalkDirFunc
type WriteFileFS ¶
type XattrFS ¶
type XattrFS interface {
FS
SetXattr(ctx context.Context, name string, attr string, data []byte, flags int) error
GetXattr(ctx context.Context, name string, attr string) ([]byte, error)
ListXattrs(ctx context.Context, name string) ([]string, error)
RemoveXattr(ctx context.Context, name string, attr string) error
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cowfs implements a copy-on-write filesystem that combines a read-only base filesystem with a writable overlay filesystem.
|
Package cowfs implements a copy-on-write filesystem that combines a read-only base filesystem with a writable overlay filesystem. |
|
fstest
command
|
|
|
net
|
|
|
tarfs implements a read-only in-memory representation of a tar archive
|
tarfs implements a read-only in-memory representation of a tar archive |