Documentation
¶
Overview ¶
Package fs implements an OS independent abstraction of a file system suitable for backup purposes.
Index ¶
- Constants
- Variables
- func HasPathPrefix(base, p string) bool
- func HasSufficientPrivilegesForVSS() error
- func IsAccessDenied(err error) bool
- func Link(oldname, newname string) error
- func Lstat(name string) (os.FileInfo, error)
- func MkdirAll(path string, perm os.FileMode) error
- func NodeCreateAt(node *restic.Node, path string) (err error)
- func NodeRestoreMetadata(node *restic.Node, path string, warn func(msg string), ...) error
- func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func PreallocateFile(wr *os.File, size int64) error
- func Readdirnames(filesystem FS, dir string, flags int) ([]string, error)
- func Remove(name string) error
- func RemoveAll(path string) error
- func ResetPermissions(path string) error
- func TempFile(dir, prefix string) (f *os.File, err error)
- type CommandReader
- type ErrorHandler
- type ExtendedFileInfo
- type FS
- type File
- type Local
- func (fs Local) Abs(path string) (string, error)
- func (fs Local) Base(path string) string
- func (fs Local) Clean(p string) string
- func (fs Local) Dir(path string) string
- func (fs Local) IsAbs(path string) bool
- func (fs Local) Join(elem ...string) string
- func (fs Local) Lstat(name string) (*ExtendedFileInfo, error)
- func (fs Local) OpenFile(name string, flag int, metadataOnly bool) (File, error)
- func (fs Local) Separator() string
- func (fs Local) VolumeName(path string) string
- type LocalVss
- type MessageHandler
- type MountPoint
- type Reader
- func (fs *Reader) Abs(p string) (string, error)
- func (fs *Reader) Base(p string) string
- func (fs *Reader) Clean(p string) string
- func (fs *Reader) Dir(p string) string
- func (fs *Reader) IsAbs(_ string) bool
- func (fs *Reader) Join(elem ...string) string
- func (fs *Reader) Lstat(name string) (*ExtendedFileInfo, error)
- func (fs *Reader) OpenFile(name string, flag int, _ bool) (f File, err error)
- func (fs *Reader) Separator() string
- func (fs *Reader) VolumeName(_ string) string
- type Track
- type VSSConfig
- type VolumeFilter
- type VssSnapshot
Constants ¶
const ( O_RDONLY int = syscall.O_RDONLY // open the file read-only. O_WRONLY int = syscall.O_WRONLY // open the file write-only. O_RDWR int = syscall.O_RDWR // open the file read-write. O_APPEND int = syscall.O_APPEND // append data to the file when writing. O_CREATE int = syscall.O_CREAT // create a new file if none exists. O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist O_SYNC int = syscall.O_SYNC // open for synchronous I/O. O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when opened. O_NONBLOCK int = syscall.O_NONBLOCK // don't block open on fifos etc. )
Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system.
const O_DIRECTORY int = syscall.O_DIRECTORY
O_DIRECTORY instructs the kernel to only open directories.
const O_NOFOLLOW int = syscall.O_NOFOLLOW
O_NOFOLLOW instructs the kernel to not follow symlinks when opening a file.
Variables ¶
var ErrFileEmpty = errors.New("no data read")
ErrFileEmpty is returned inside a *os.PathError by Read() for the file opened from the fs provided by Reader when no data could be read and AllowEmptyFile is not set.
Functions ¶
func HasPathPrefix ¶
HasPathPrefix returns true if p is a subdir of (or a file within) base. It assumes a file system which is case sensitive. If the paths are not of the same type (one is relative, the other is absolute), false is returned.
func HasSufficientPrivilegesForVSS ¶
func HasSufficientPrivilegesForVSS() error
HasSufficientPrivilegesForVSS returns true if the user is allowed to use VSS.
func IsAccessDenied ¶ added in v0.17.0
IsAccessDenied checks if the error is due to permission error.
func Link ¶
Link creates newname as a hard link to oldname. If there is an error, it will be of type *LinkError.
func Lstat ¶
Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.
func MkdirAll ¶
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 NodeCreateAt ¶ added in v0.18.0
NodeCreateAt creates the node at the given path but does NOT restore node meta data.
func NodeRestoreMetadata ¶ added in v0.18.0
func NodeRestoreMetadata(node *restic.Node, path string, warn func(msg string), xattrSelectFilter func(xattrName string) bool) error
NodeRestoreMetadata restores node metadata
func OpenFile ¶
OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.
func Readdirnames ¶ added in v0.17.0
Readdirnames returns a list of file in a directory. Flags are passed to fs.OpenFile. O_RDONLY and O_DIRECTORY are implied.
func Remove ¶
Remove removes the named file or directory. If there is an error, it will be of type *PathError.
func RemoveAll ¶
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func ResetPermissions ¶ added in v0.17.0
ResetPermissions resets the permissions of the file at the specified path
Types ¶
type CommandReader ¶ added in v0.17.0
type CommandReader struct {
// contains filtered or unexported fields
}
CommandReader wraps a command such that its standard output can be read using a io.ReadCloser. Close() waits for the command to terminate, reporting any error back to the caller.
func NewCommandReader ¶ added in v0.17.0
func (*CommandReader) Close ¶ added in v0.17.0
func (fp *CommandReader) Close() error
type ErrorHandler ¶
ErrorHandler is used to report errors via callback.
type ExtendedFileInfo ¶
type ExtendedFileInfo struct { Name string Mode os.FileMode DeviceID uint64 // ID of device containing the file Inode uint64 // Inode number Links uint64 // Number of hard links UID uint32 // owner user ID GID uint32 // owner group ID Device uint64 // Device ID (if this is a device file) BlockSize int64 // block size for filesystem IO Blocks int64 // number of allocated filesystem blocks Size int64 // file size in byte AccessTime time.Time // last access time stamp ModTime time.Time // last (content) modification time stamp ChangeTime time.Time // last status change time stamp // contains filtered or unexported fields }
ExtendedFileInfo is an extended stat_t, filled with attributes that are supported by most operating systems. The original FileInfo is embedded.
func ExtendedStat ¶
func ExtendedStat(fi os.FileInfo) *ExtendedFileInfo
ExtendedStat returns an ExtendedFileInfo constructed from the os.FileInfo.
func (*ExtendedFileInfo) RecallOnDataAccess ¶ added in v0.18.0
func (*ExtendedFileInfo) RecallOnDataAccess() (bool, error)
RecallOnDataAccess checks windows-specific attributes to determine if a file is a cloud-only placeholder.
type FS ¶
type FS interface { // OpenFile opens a file or directory for reading. // // If metadataOnly is set, an implementation MUST return a File object for // arbitrary file types including symlinks. The implementation may internally use // the given file path or a file handle. In particular, an implementation may // delay actually accessing the underlying filesystem. // // Only the O_NOFOLLOW and O_DIRECTORY flags are supported. OpenFile(name string, flag int, metadataOnly bool) (File, error) Lstat(name string) (*ExtendedFileInfo, error) Join(elem ...string) string Separator() string Abs(path string) (string, error) Clean(path string) string VolumeName(path string) string IsAbs(path string) bool Dir(path string) string Base(path string) string }
FS bundles all methods needed for a file system.
type File ¶
type File interface { // MakeReadable reopens a File that was opened metadataOnly for reading. // The method must not be called for files that are opened for reading. // If possible, the underlying file should be reopened atomically. // MakeReadable must work for files and directories. MakeReadable() error io.Reader io.Closer Readdirnames(n int) ([]string, error) Stat() (*ExtendedFileInfo, error) // ToNode returns a restic.Node for the File. The internally used os.FileInfo // must be consistent with that returned by Stat(). In particular, the metadata // returned by consecutive calls to Stat() and ToNode() must match. ToNode(ignoreXattrListError bool) (*restic.Node, error) }
File is an open file on a file system. When opened as metadataOnly, an implementation may opt to perform filesystem operations using the filepath instead of actually opening the file.
type Local ¶
type Local struct{}
Local is the local file system. Most methods are just passed on to the stdlib.
func (Local) Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (Local) Join ¶
Join joins any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.
func (Local) Lstat ¶
func (fs Local) Lstat(name string) (*ExtendedFileInfo, error)
Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.
func (Local) OpenFile ¶
OpenFile opens a file or directory for reading.
If metadataOnly is set, an implementation MUST return a File object for arbitrary file types including symlinks. The implementation may internally use the given file path or a file handle. In particular, an implementation may delay actually accessing the underlying filesystem.
Only the O_NOFOLLOW and O_DIRECTORY flags are supported.
func (Local) Separator ¶
Separator returns the OS and FS dependent separator for dirs/subdirs/files.
func (Local) VolumeName ¶
VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:" on Windows. Given "\\host\share\foo" it returns "\\host\share". On other platforms it returns "".
type LocalVss ¶
type LocalVss struct { FS // contains filtered or unexported fields }
LocalVss is a wrapper around the local file system which uses windows volume shadow copy service (VSS) in a transparent way.
func NewLocalVss ¶
func NewLocalVss(msgError ErrorHandler, msgMessage MessageHandler, cfg VSSConfig) *LocalVss
NewLocalVss creates a new wrapper around the windows filesystem using volume shadow copy service to access locked files.
func (*LocalVss) DeleteSnapshots ¶
func (fs *LocalVss) DeleteSnapshots()
DeleteSnapshots deletes all snapshots that were created automatically.
type MessageHandler ¶
type MessageHandler func(msg string, args ...interface{})
MessageHandler is used to report errors/messages via callbacks.
type MountPoint ¶
type MountPoint struct { }
MountPoint is a dummy for non-windows platforms to let client code compile.
func (*MountPoint) GetSnapshotDeviceObject ¶
func (p *MountPoint) GetSnapshotDeviceObject() string
GetSnapshotDeviceObject returns root path to access the snapshot files and folders.
func (*MountPoint) IsSnapshotted ¶
func (p *MountPoint) IsSnapshotted() bool
IsSnapshotted is true if this mount point was snapshotted successfully.
type Reader ¶
type Reader struct { Name string io.ReadCloser // for FileInfo Mode os.FileMode ModTime time.Time Size int64 AllowEmptyFile bool // contains filtered or unexported fields }
Reader is a file system which provides a directory with a single file. When this file is opened for reading, the reader is passed through. The file can be opened once, all subsequent open calls return syscall.EIO. For Lstat(), the provided FileInfo is returned.
func (*Reader) Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
For the Reader, all paths are absolute.
func (*Reader) IsAbs ¶
IsAbs reports whether the path is absolute. For the Reader, this is always the case.
func (*Reader) Join ¶
Join joins any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.
func (*Reader) Lstat ¶
func (fs *Reader) Lstat(name string) (*ExtendedFileInfo, error)
Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *os.PathError.
func (*Reader) Separator ¶
Separator returns the OS and FS dependent separator for dirs/subdirs/files.
func (*Reader) VolumeName ¶
VolumeName returns leading volume name, for the Reader file system it's always the empty string.
type Track ¶
type Track struct {
FS
}
Track is a wrapper around another file system which installs finalizers for open files which call panic() when they are not closed when the garbage collector releases them. This can be used to find resource leaks via open files.
type VSSConfig ¶ added in v0.17.0
type VSSConfig struct { ExcludeAllMountPoints bool `option:"exclude-all-mount-points" help:"exclude mountpoints from snapshotting on all volumes"` ExcludeVolumes string `` /* 136-byte string literal not displayed */ Timeout time.Duration `option:"timeout" help:"time that the VSS can spend creating snapshot before timing out"` Provider string `option:"provider" help:"VSS provider identifier which will be used for snapshotting"` }
VSSConfig holds extended options of windows volume shadow copy service.
func NewVSSConfig ¶ added in v0.17.0
func NewVSSConfig() VSSConfig
NewVSSConfig returns a new VSSConfig with the default values filled in.
type VolumeFilter ¶ added in v0.17.0
VolumeFilter is used to filter volumes by it's mount point or GUID path.
type VssSnapshot ¶
type VssSnapshot struct {
// contains filtered or unexported fields
}
VssSnapshot is a dummy for non-windows platforms to let client code compile.
func NewVssSnapshot ¶
func NewVssSnapshot(_ string, _ string, _ time.Duration, _ VolumeFilter, _ ErrorHandler) (VssSnapshot, error)
NewVssSnapshot creates a new vss snapshot. If creating the snapshots doesn't finish within the timeout an error is returned.
func (*VssSnapshot) Delete ¶
func (p *VssSnapshot) Delete() error
Delete deletes the created snapshot.
func (*VssSnapshot) GetSnapshotDeviceObject ¶
func (p *VssSnapshot) GetSnapshotDeviceObject() string
GetSnapshotDeviceObject returns root path to access the snapshot files and folders.