Documentation ¶
Index ¶
- Constants
- Variables
- func Canonicalize(file string) (string, error)
- func CommonPrefix(first, second string) string
- func ExpandTilde(path string) (string, error)
- func IsInternal(file string) bool
- func IsParent(path, parent string) bool
- func IsTemporary(name string) bool
- func TempName(name string) string
- func TempNameWithPrefix(name, prefix string) string
- func UnicodeLowercase(s string) string
- func WindowsInvalidFilename(name string) bool
- type BasicFilesystem
- func (f *BasicFilesystem) Chmod(name string, mode FileMode) error
- func (f *BasicFilesystem) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (f *BasicFilesystem) Create(name string) (File, error)
- func (f *BasicFilesystem) CreateSymlink(target, name string) error
- func (f *BasicFilesystem) DirNames(name string) ([]string, error)
- func (f *BasicFilesystem) Glob(pattern string) ([]string, error)
- func (f *BasicFilesystem) Hide(name string) error
- func (f *BasicFilesystem) Lchown(name string, uid, gid int) error
- func (f *BasicFilesystem) Lstat(name string) (FileInfo, error)
- func (f *BasicFilesystem) Mkdir(name string, perm FileMode) error
- func (f *BasicFilesystem) MkdirAll(path string, perm FileMode) error
- func (f *BasicFilesystem) Open(name string) (File, error)
- func (f *BasicFilesystem) OpenFile(name string, flags int, mode FileMode) (File, error)
- func (f *BasicFilesystem) ReadSymlink(name string) (string, error)
- func (f *BasicFilesystem) Remove(name string) error
- func (f *BasicFilesystem) RemoveAll(name string) error
- func (f *BasicFilesystem) Rename(oldpath, newpath string) error
- func (f *BasicFilesystem) Roots() ([]string, error)
- func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool
- func (f *BasicFilesystem) Stat(name string) (FileInfo, error)
- func (BasicFilesystem) SymlinksSupported() bool
- func (f *BasicFilesystem) Type() FilesystemType
- func (f *BasicFilesystem) URI() string
- func (f *BasicFilesystem) Unhide(name string) error
- func (f *BasicFilesystem) Usage(name string) (Usage, error)
- func (f *BasicFilesystem) Walk(root string, walkFn WalkFunc) error
- func (f *BasicFilesystem) Watch(name string, ignore Matcher, ctx context.Context, ignorePerms bool) (<-chan Event, <-chan error, error)
- type ErrWatchEventOutsideRoot
- type Event
- type EventType
- type File
- type FileInfo
- type FileMode
- type Filesystem
- type FilesystemType
- type MatchResult
- type Matcher
- type MtimeFS
- func (f *MtimeFS) Chtimes(name string, atime, mtime time.Time) error
- func (f *MtimeFS) Create(name string) (File, error)
- func (f *MtimeFS) Lstat(name string) (FileInfo, error)
- func (f *MtimeFS) Open(name string) (File, error)
- func (f *MtimeFS) OpenFile(name string, flags int, mode FileMode) (File, error)
- func (f *MtimeFS) Stat(name string) (FileInfo, error)
- func (f *MtimeFS) Walk(root string, walkFn WalkFunc) error
- type MtimeFSOption
- type Usage
- type WalkFunc
Constants ¶
const ( WindowsTempPrefix = "~syncthing~" UnixTempPrefix = ".syncthing." )
const ModePerm = FileMode(os.ModePerm)
const ModeSetgid = FileMode(os.ModeSetgid)
const ModeSetuid = FileMode(os.ModeSetuid)
const ModeSticky = FileMode(os.ModeSticky)
const ModeSymlink = FileMode(os.ModeSymlink)
const ModeType = FileMode(os.ModeType)
const OptAppend = os.O_APPEND
const OptCreate = os.O_CREATE
const OptExclusive = os.O_EXCL
const OptReadOnly = os.O_RDONLY
const OptReadWrite = os.O_RDWR
const OptSync = os.O_SYNC
const OptTruncate = os.O_TRUNC
const OptWriteOnly = os.O_WRONLY
const PathSeparator = os.PathSeparator
Variables ¶
var ( ErrInvalidFilename = errors.New("filename is invalid") ErrNotRelative = errors.New("not a relative path") )
var ErrWatchNotSupported = errors.New("watching is not supported")
var IsExist = os.IsExist
IsExist is the equivalent of os.IsExist
var IsNotExist = os.IsNotExist
IsNotExist is the equivalent of os.IsNotExist
var IsPathSeparator = os.IsPathSeparator
IsPathSeparator is the equivalent of os.IsPathSeparator
var IsPermission = os.IsPermission
IsPermission is the equivalent of os.IsPermission
var SkipDir = filepath.SkipDir
SkipDir is used as a return value from WalkFuncs to indicate that the directory named in the call is to be skipped. It is not returned as an error by any function.
var TempPrefix string
Functions ¶
func Canonicalize ¶ added in v0.14.46
Canonicalize checks that the file path is valid and returns it in the "canonical" form: - /foo/bar -> foo/bar - / -> "."
func CommonPrefix ¶ added in v1.1.4
func ExpandTilde ¶ added in v0.14.37
func IsInternal ¶ added in v0.14.38
IsInternal returns true if the file, as a path relative to the folder root, represents an internal file that should always be ignored. The file path must be clean (i.e., in canonical shortest form).
func IsParent ¶ added in v1.0.0
IsParent compares paths purely lexicographically, meaning it returns false if path and parent aren't both absolute or relative.
func IsTemporary ¶ added in v0.14.38
IsTemporary is true if the file name has the temporary prefix. Regardless of the normally used prefix, the standard Windows and Unix temp prefixes are always recognized as temp files.
func TempNameWithPrefix ¶ added in v0.14.44
func UnicodeLowercase ¶ added in v0.14.41
func WindowsInvalidFilename ¶ added in v0.14.41
Types ¶
type BasicFilesystem ¶ added in v0.14.13
type BasicFilesystem struct {
// contains filtered or unexported fields
}
The BasicFilesystem implements all aspects by delegating to package os. All paths are relative to the root and cannot (should not) escape the root directory.
func (*BasicFilesystem) Chmod ¶ added in v0.14.13
func (f *BasicFilesystem) Chmod(name string, mode FileMode) error
func (*BasicFilesystem) Create ¶ added in v0.14.13
func (f *BasicFilesystem) Create(name string) (File, error)
func (*BasicFilesystem) CreateSymlink ¶ added in v0.14.13
func (f *BasicFilesystem) CreateSymlink(target, name string) error
func (*BasicFilesystem) DirNames ¶ added in v0.14.13
func (f *BasicFilesystem) DirNames(name string) ([]string, error)
func (*BasicFilesystem) Glob ¶ added in v0.14.37
func (f *BasicFilesystem) Glob(pattern string) ([]string, error)
func (*BasicFilesystem) Hide ¶ added in v0.14.37
func (f *BasicFilesystem) Hide(name string) error
Hide is a noop on unix, as hiding files requires renaming them. We still check that the relative path does not try to escape the root
func (*BasicFilesystem) Lchown ¶ added in v1.1.0
func (f *BasicFilesystem) Lchown(name string, uid, gid int) error
func (*BasicFilesystem) Lstat ¶ added in v0.14.13
func (f *BasicFilesystem) Lstat(name string) (FileInfo, error)
func (*BasicFilesystem) Mkdir ¶ added in v0.14.13
func (f *BasicFilesystem) Mkdir(name string, perm FileMode) error
func (*BasicFilesystem) MkdirAll ¶ added in v0.14.37
func (f *BasicFilesystem) MkdirAll(path string, perm FileMode) error
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (*BasicFilesystem) Open ¶ added in v0.14.13
func (f *BasicFilesystem) Open(name string) (File, error)
func (*BasicFilesystem) ReadSymlink ¶ added in v0.14.13
func (f *BasicFilesystem) ReadSymlink(name string) (string, error)
func (*BasicFilesystem) Remove ¶ added in v0.14.13
func (f *BasicFilesystem) Remove(name string) error
func (*BasicFilesystem) RemoveAll ¶ added in v0.14.37
func (f *BasicFilesystem) RemoveAll(name string) error
func (*BasicFilesystem) Rename ¶ added in v0.14.13
func (f *BasicFilesystem) Rename(oldpath, newpath string) error
func (*BasicFilesystem) Roots ¶ added in v0.14.37
func (f *BasicFilesystem) Roots() ([]string, error)
func (*BasicFilesystem) SameFile ¶ added in v0.14.44
func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool
func (*BasicFilesystem) Stat ¶ added in v0.14.13
func (f *BasicFilesystem) Stat(name string) (FileInfo, error)
func (BasicFilesystem) SymlinksSupported ¶ added in v0.14.13
func (BasicFilesystem) SymlinksSupported() bool
func (*BasicFilesystem) Type ¶ added in v0.14.37
func (f *BasicFilesystem) Type() FilesystemType
func (*BasicFilesystem) URI ¶ added in v0.14.37
func (f *BasicFilesystem) URI() string
func (*BasicFilesystem) Unhide ¶ added in v0.14.37
func (f *BasicFilesystem) Unhide(name string) error
Unhide is a noop on unix, as unhiding files requires renaming them. We still check that the relative path does not try to escape the root
func (*BasicFilesystem) Usage ¶ added in v0.14.37
func (f *BasicFilesystem) Usage(name string) (Usage, error)
type ErrWatchEventOutsideRoot ¶ added in v1.2.0
type ErrWatchEventOutsideRoot struct {
// contains filtered or unexported fields
}
func (*ErrWatchEventOutsideRoot) Error ¶ added in v1.2.0
func (e *ErrWatchEventOutsideRoot) Error() string
type EventType ¶ added in v0.14.40
type EventType int
type File ¶ added in v0.14.13
type File interface { io.Closer io.Reader io.ReaderAt io.Seeker io.Writer io.WriterAt Name() string Truncate(size int64) error Stat() (FileInfo, error) Sync() error }
The File interface abstracts access to a regular file, being a somewhat smaller interface than os.File
type FileInfo ¶ added in v0.14.13
type FileInfo interface { // Standard things present in os.FileInfo Name() string Mode() FileMode Size() int64 ModTime() time.Time IsDir() bool // Extensions IsRegular() bool IsSymlink() bool Owner() int Group() int }
The FileInfo interface is almost the same as os.FileInfo, but with the Sys method removed (as we don't want to expose whatever is underlying) and with a couple of convenience methods added.
type Filesystem ¶ added in v0.14.13
type Filesystem interface { Chmod(name string, mode FileMode) error Lchown(name string, uid, gid int) error Chtimes(name string, atime time.Time, mtime time.Time) error Create(name string) (File, error) CreateSymlink(target, name string) error DirNames(name string) ([]string, error) Lstat(name string) (FileInfo, error) Mkdir(name string, perm FileMode) error MkdirAll(name string, perm FileMode) error Open(name string) (File, error) OpenFile(name string, flags int, mode FileMode) (File, error) ReadSymlink(name string) (string, error) Remove(name string) error RemoveAll(name string) error Rename(oldname, newname string) error Stat(name string) (FileInfo, error) SymlinksSupported() bool Walk(name string, walkFn WalkFunc) error // If setup fails, returns non-nil error, and if afterwards a fatal (!) // error occurs, sends that error on the channel. Afterwards this watch // can be considered stopped. Watch(path string, ignore Matcher, ctx context.Context, ignorePerms bool) (<-chan Event, <-chan error, error) Hide(name string) error Unhide(name string) error Glob(pattern string) ([]string, error) Roots() ([]string, error) Usage(name string) (Usage, error) Type() FilesystemType URI() string SameFile(fi1, fi2 FileInfo) bool }
The Filesystem interface abstracts access to the file system.
func NewFilesystem ¶ added in v0.14.37
func NewFilesystem(fsType FilesystemType, uri string) Filesystem
func NewWalkFilesystem ¶ added in v0.14.28
func NewWalkFilesystem(next Filesystem) Filesystem
type FilesystemType ¶ added in v0.14.37
type FilesystemType int
const ( FilesystemTypeBasic FilesystemType = iota // default is basic FilesystemTypeFake )
func (FilesystemType) MarshalText ¶ added in v0.14.37
func (t FilesystemType) MarshalText() ([]byte, error)
func (FilesystemType) String ¶ added in v0.14.37
func (t FilesystemType) String() string
func (*FilesystemType) UnmarshalText ¶ added in v0.14.37
func (t *FilesystemType) UnmarshalText(bs []byte) error
type MatchResult ¶ added in v0.14.40
type MatchResult interface {
IsIgnored() bool
}
type MtimeFS ¶
type MtimeFS struct { Filesystem // contains filtered or unexported fields }
The MtimeFS is a filesystem with nanosecond mtime precision, regardless of what shenanigans the underlying filesystem gets up to. A nil MtimeFS just does the underlying operations with no additions.
func NewMtimeFS ¶
func NewMtimeFS(underlying Filesystem, db database, options ...MtimeFSOption) *MtimeFS
type MtimeFSOption ¶ added in v0.14.41
type MtimeFSOption func(*MtimeFS)
func WithCaseInsensitivity ¶ added in v0.14.41
func WithCaseInsensitivity(v bool) MtimeFSOption
type WalkFunc ¶ added in v0.14.13
WalkFunc is the type of the function called for each file or directory visited by Walk. The path argument contains the argument to Walk as a prefix; that is, if Walk is called with "dir", which is a directory containing the file "a", the walk function will be called with argument "dir/a". The info argument is the FileInfo for the named path.
If there was a problem walking to the file or directory named by path, the incoming error will describe the problem and the function can decide how to handle that error (and Walk will not descend into that directory). If an error is returned, processing stops. The sole exception is when the function returns the special value SkipDir. If the function returns SkipDir when invoked on a directory, Walk skips the directory's contents entirely. If the function returns SkipDir when invoked on a non-directory file, Walk skips the remaining files in the containing directory.