Documentation ¶
Index ¶
- Variables
- func TrimVolume(filePath string) string
- type BackupFs
- func (fs *BackupFs) Chmod(name string, mode os.FileMode) error
- func (fs *BackupFs) Chown(name string, uid, gid int) error
- func (fs *BackupFs) Chtimes(name string, atime, mtime time.Time) error
- func (fs *BackupFs) Create(name string) (File, error)
- func (fs *BackupFs) ForceBackup(name string) (err error)
- func (fs *BackupFs) GetBackupFs() afero.Fs
- func (fs *BackupFs) GetBaseFs() afero.Fs
- func (fs *BackupFs) LchownIfPossible(name string, uid, gid int) error
- func (fs *BackupFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (fs *BackupFs) Map() map[string]os.FileInfo
- func (fs *BackupFs) MarshalJSON() ([]byte, error)
- func (fs *BackupFs) Mkdir(name string, perm os.FileMode) error
- func (fs *BackupFs) MkdirAll(name string, perm os.FileMode) error
- func (fs *BackupFs) Name() string
- func (fs *BackupFs) Open(name string) (File, error)
- func (fs *BackupFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (fs *BackupFs) ReadlinkIfPossible(name string) (string, error)
- func (fs *BackupFs) Remove(name string) error
- func (fs *BackupFs) RemoveAll(name string) error
- func (fs *BackupFs) Rename(oldname, newname string) error
- func (fs *BackupFs) Rollback() error
- func (fs *BackupFs) Stat(name string) (os.FileInfo, error)
- func (fs *BackupFs) SymlinkIfPossible(oldname, newname string) error
- func (fs *BackupFs) UnmarshalJSON(data []byte) error
- type File
- type HiddenFs
- func (s *HiddenFs) Chmod(name string, mode os.FileMode) error
- func (s *HiddenFs) Chown(name string, uid, gid int) error
- func (s *HiddenFs) Chtimes(name string, atime, mtime time.Time) error
- func (s *HiddenFs) Create(name string) (File, error)
- func (s *HiddenFs) LchownIfPossible(name string, uid, gid int) error
- func (s *HiddenFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (s *HiddenFs) Mkdir(name string, perm os.FileMode) error
- func (s *HiddenFs) MkdirAll(name string, perm os.FileMode) error
- func (s *HiddenFs) Name() string
- func (s *HiddenFs) Open(name string) (File, error)
- func (s *HiddenFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (s *HiddenFs) ReadlinkIfPossible(name string) (string, error)
- func (s *HiddenFs) Remove(name string) error
- func (s *HiddenFs) RemoveAll(name string) error
- func (s *HiddenFs) Rename(oldname, newname string) error
- func (s *HiddenFs) Stat(name string) (os.FileInfo, error)
- func (s *HiddenFs) SymlinkIfPossible(oldname, newname string) error
- type HiddenFsFile
- func (hf *HiddenFsFile) Close() error
- func (hf *HiddenFsFile) Name() string
- func (hf *HiddenFsFile) Read(p []byte) (n int, err error)
- func (hf *HiddenFsFile) ReadAt(p []byte, off int64) (n int, err error)
- func (hf *HiddenFsFile) Readdir(count int) ([]os.FileInfo, error)
- func (hf *HiddenFsFile) Readdirnames(count int) ([]string, error)
- func (hf *HiddenFsFile) Seek(offset int64, whence int) (int64, error)
- func (hf *HiddenFsFile) Stat() (os.FileInfo, error)
- func (hf *HiddenFsFile) Sync() error
- func (hf *HiddenFsFile) Truncate(size int64) error
- func (hf *HiddenFsFile) Write(p []byte) (n int, err error)
- func (hf *HiddenFsFile) WriteAt(p []byte, off int64) (n int, err error)
- func (hf *HiddenFsFile) WriteString(s string) (ret int, err error)
- type LinkOwner
- type PrefixFile
- func (pf *PrefixFile) Close() error
- func (pf *PrefixFile) Name() string
- func (pf *PrefixFile) Read(p []byte) (n int, err error)
- func (pf *PrefixFile) ReadAt(p []byte, off int64) (n int, err error)
- func (pf *PrefixFile) Readdir(count int) ([]os.FileInfo, error)
- func (pf *PrefixFile) Readdirnames(n int) ([]string, error)
- func (pf *PrefixFile) Seek(offset int64, whence int) (int64, error)
- func (pf *PrefixFile) Stat() (os.FileInfo, error)
- func (pf *PrefixFile) Sync() error
- func (pf *PrefixFile) Truncate(size int64) error
- func (pf *PrefixFile) Write(p []byte) (n int, err error)
- func (pf *PrefixFile) WriteAt(p []byte, off int64) (n int, err error)
- func (pf *PrefixFile) WriteString(s string) (ret int, err error)
- type PrefixFs
- func (s *PrefixFs) Chmod(name string, mode os.FileMode) error
- func (s *PrefixFs) Chown(name string, uid, gid int) error
- func (s *PrefixFs) Chtimes(name string, atime, mtime time.Time) error
- func (s *PrefixFs) Create(name string) (File, error)
- func (s *PrefixFs) LchownIfPossible(name string, uid, gid int) error
- func (s *PrefixFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (s *PrefixFs) Mkdir(name string, perm os.FileMode) error
- func (s *PrefixFs) MkdirAll(name string, perm os.FileMode) error
- func (s *PrefixFs) Name() string
- func (s *PrefixFs) Open(name string) (File, error)
- func (s *PrefixFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (s *PrefixFs) ReadlinkIfPossible(name string) (string, error)
- func (s *PrefixFs) Remove(name string) error
- func (s *PrefixFs) RemoveAll(name string) error
- func (s *PrefixFs) Rename(oldname, newname string) error
- func (s *PrefixFs) Stat(name string) (os.FileInfo, error)
- func (s *PrefixFs) SymlinkIfPossible(oldname, newname string) error
- type VolumeFs
- func (v *VolumeFs) Chmod(name string, mode os.FileMode) error
- func (v *VolumeFs) Chown(name string, uid, gid int) error
- func (v *VolumeFs) Chtimes(name string, atime, mtime time.Time) error
- func (v *VolumeFs) Create(name string) (File, error)
- func (v *VolumeFs) LchownIfPossible(name string, uid, gid int) error
- func (v *VolumeFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (v *VolumeFs) Mkdir(name string, perm os.FileMode) error
- func (v *VolumeFs) MkdirAll(name string, perm os.FileMode) error
- func (v *VolumeFs) Name() string
- func (v *VolumeFs) Open(name string) (File, error)
- func (v *VolumeFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (v *VolumeFs) ReadlinkIfPossible(name string) (string, error)
- func (v *VolumeFs) Remove(name string) error
- func (v *VolumeFs) RemoveAll(name string) error
- func (v *VolumeFs) Rename(oldname, newname string) error
- func (v *VolumeFs) Stat(name string) (os.FileInfo, error)
- func (v *VolumeFs) SymlinkIfPossible(oldname, newname string) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRollbackFailed is returned when the rollback fails due to e.g. network problems. // when this error is returned it might make sense to retry the rollback ErrRollbackFailed = errors.New("rollback failed") // ErrNoSymlink is returned when we ar enot able to backup symlinks due to any of the base filesystem or // the target backup filesystem not supporting symlinks. ErrNoSymlink = afero.ErrNoSymlink // ErrBaseFsNoSymlink is returned in case that the base filesystem does not support symlinks ErrBaseFsNoSymlink = fmt.Errorf("base filesystem: %w", ErrNoSymlink) // ErrBackupFsNoSymlink is returned in case that the backup target filesystem does not support symlinks ErrBackupFsNoSymlink = fmt.Errorf("backup filesystem: %w", ErrNoSymlink) )
var ( ErrHiddenNotExist = fmt.Errorf("hidden: %w", os.ErrNotExist) ErrHiddenPermission = fmt.Errorf("hidden: %w", os.ErrPermission) )
Functions ¶
func TrimVolume ¶ added in v0.9.0
TrimVolume trims the volume prefix of a given filepath. C:\A\B\C -> \A\B\C highly OS-dependent. On unix systems there is no such thing as a volume path prefix.
Types ¶
type BackupFs ¶
type BackupFs struct {
// contains filtered or unexported fields
}
BackupFs is a file system abstraction that takes two underlying filesystems. One filesystem that is is being used to read and write files and a second filesystem which is used as backup target in case that a file of the base filesystem is about to be modified.
func NewBackupFs ¶
NewBackupFs creates a new layered backup file system that backups files from fs to backup in case that an existing file in fs is about to be overwritten or removed.
func NewBackupFsWithVolume ¶ added in v0.9.2
NewBackupFsWithVolume creates a new layered backup file system that backups files from fs to backup in case that an existing file in fs is about to be overwritten or removed. Contrary to the normal backupfs this variant allows to use absolute windows paths (C:\A\B\C instead of \A\B\C)
func (*BackupFs) Create ¶
Create creates a file in the filesystem, returning the file and an error, if any happens.
func (*BackupFs) ForceBackup ¶ added in v0.8.0
func (*BackupFs) GetBackupFs ¶ added in v0.4.7
GetBackupFs returns the fs layer that is used to store the backups
func (*BackupFs) GetBaseFs ¶ added in v0.4.7
GetBaseFs returns the fs layer that is being written to
func (*BackupFs) LchownIfPossible ¶ added in v0.6.0
LchownIfPossible does not fallback to chown. It does return an error in case that lchown cannot be called.
func (*BackupFs) LstatIfPossible ¶ added in v0.4.0
func (*BackupFs) MarshalJSON ¶ added in v0.2.0
func (*BackupFs) Mkdir ¶
Mkdir creates a directory in the filesystem, return an error if any happens.
func (*BackupFs) MkdirAll ¶
MkdirAll creates a directory path and all parents that does not exist yet.
func (*BackupFs) Open ¶
Open opens a file, returning it or an error, if any happens. This returns a ready only file
func (*BackupFs) ReadlinkIfPossible ¶ added in v0.4.0
func (*BackupFs) Remove ¶
Remove removes a file identified by name, returning an error, if any happens.
func (*BackupFs) RemoveAll ¶
RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil). not supported
func (*BackupFs) Rollback ¶ added in v0.2.0
Rollback tries to rollback the backup back to the base system removing any new files for the base system and restoring any old files from the backup Best effort, any errors due to filesystem modification on the backup site are skipped This is a heavy weight operation which blocks the file system until the rollback is done.
func (*BackupFs) Stat ¶
Stat returns a FileInfo describing the named file, or an error, if any happens. Stat only looks at the base filesystem and returns the stat of the files at the specified path
func (*BackupFs) SymlinkIfPossible ¶ added in v0.4.0
SymlinkIfPossible changes the access and modification times of the named file
func (*BackupFs) UnmarshalJSON ¶ added in v0.2.0
type HiddenFs ¶ added in v0.7.1
type HiddenFs struct {
// contains filtered or unexported fields
}
HiddenFs hides everything inside of a list of directory prefixes from the user. Does NOT hide the directory itself. This abstraction is needed in order to prevent infinite backup loops in case that BackupFs and HiddenFs are used together where the backup location of BackupFs is a prefixed path on the same underlying base filesystem (e.g. os filesystem). In case you want to prevent accidentally falling into an infinite recursion when walking and modifying files in the directory tree of a BackupFs struct which also contains the backup location that is modified while walking over it via the BackupFs layer.
Writing to the hidden paths results in a os.ErrPermission error Reading/Stat/Lstat from the directories or files results in os.ErrNotExist errors
func NewHiddenFs ¶ added in v0.7.1
NewHiddenFs hides away anthing beneath the specified paths.
func (*HiddenFs) Chtimes ¶ added in v0.7.1
Chtimes changes the access and modification times of the named file
func (*HiddenFs) Create ¶ added in v0.7.1
Create creates a file in the filesystem, returning the file and an error, if any happens.
func (*HiddenFs) LchownIfPossible ¶ added in v0.7.1
func (*HiddenFs) LstatIfPossible ¶ added in v0.7.1
LstatIfPossible will call Lstat if the filesystem itself is, or it delegates to, the os filesystem. Else it will call Stat. In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not.
func (*HiddenFs) Mkdir ¶ added in v0.7.1
Mkdir creates a directory in the filesystem, return an error if any happens.
func (*HiddenFs) MkdirAll ¶ added in v0.7.1
MkdirAll creates a directory path and all parents that does not exist yet.
func (*HiddenFs) Open ¶ added in v0.7.1
Open opens a file, returning it or an error, if any happens. This returns a ready only file
func (*HiddenFs) OpenFile ¶ added in v0.7.1
OpenFile opens a file using the given flags and the given mode.
func (*HiddenFs) ReadlinkIfPossible ¶ added in v0.7.1
func (*HiddenFs) Remove ¶ added in v0.7.1
Remove removes a file identified by name, returning an error, if any happens.
func (*HiddenFs) RemoveAll ¶ added in v0.7.1
RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).
func (*HiddenFs) Stat ¶ added in v0.7.1
Stat returns a FileInfo describing the named file, or an error, if any happens.
func (*HiddenFs) SymlinkIfPossible ¶ added in v0.7.1
SymlinkIfPossible changes the access and modification times of the named file
type HiddenFsFile ¶ added in v0.7.1
type HiddenFsFile struct {
// contains filtered or unexported fields
}
func (*HiddenFsFile) Close ¶ added in v0.7.1
func (hf *HiddenFsFile) Close() error
func (*HiddenFsFile) Name ¶ added in v0.7.1
func (hf *HiddenFsFile) Name() string
func (*HiddenFsFile) Read ¶ added in v0.7.1
func (hf *HiddenFsFile) Read(p []byte) (n int, err error)
func (*HiddenFsFile) ReadAt ¶ added in v0.7.1
func (hf *HiddenFsFile) ReadAt(p []byte, off int64) (n int, err error)
func (*HiddenFsFile) Readdir ¶ added in v0.7.1
func (hf *HiddenFsFile) Readdir(count int) ([]os.FileInfo, error)
func (*HiddenFsFile) Readdirnames ¶ added in v0.7.1
func (hf *HiddenFsFile) Readdirnames(count int) ([]string, error)
func (*HiddenFsFile) Seek ¶ added in v0.7.1
func (hf *HiddenFsFile) Seek(offset int64, whence int) (int64, error)
func (*HiddenFsFile) Sync ¶ added in v0.7.1
func (hf *HiddenFsFile) Sync() error
func (*HiddenFsFile) Truncate ¶ added in v0.7.1
func (hf *HiddenFsFile) Truncate(size int64) error
func (*HiddenFsFile) Write ¶ added in v0.7.1
func (hf *HiddenFsFile) Write(p []byte) (n int, err error)
func (*HiddenFsFile) WriteAt ¶ added in v0.7.1
func (hf *HiddenFsFile) WriteAt(p []byte, off int64) (n int, err error)
func (*HiddenFsFile) WriteString ¶ added in v0.7.1
func (hf *HiddenFsFile) WriteString(s string) (ret int, err error)
type LinkOwner ¶ added in v0.6.0
LinkOwner is an optional interface in Afero. It is only implemented by the filesystems saying so.
type PrefixFile ¶
type PrefixFile struct {
// contains filtered or unexported fields
}
func (*PrefixFile) Close ¶
func (pf *PrefixFile) Close() error
func (*PrefixFile) Name ¶
func (pf *PrefixFile) Name() string
func (*PrefixFile) Readdirnames ¶
func (pf *PrefixFile) Readdirnames(n int) ([]string, error)
func (*PrefixFile) Sync ¶
func (pf *PrefixFile) Sync() error
func (*PrefixFile) Truncate ¶
func (pf *PrefixFile) Truncate(size int64) error
func (*PrefixFile) WriteString ¶
func (pf *PrefixFile) WriteString(s string) (ret int, err error)
type PrefixFs ¶
type PrefixFs struct {
// contains filtered or unexported fields
}
PrefixFs, contrary to BasePathFs, does abstract away the existence of a base path. The prefixed path is seen as the root directory.
func NewPrefixFs ¶
NewPrefixFs creates a new file system abstraction that forces any path to be prepended with the provided prefix. the existence of the prefixPath existing is hidden away (errors might show full paths).
func (*PrefixFs) Create ¶
Create creates a file in the filesystem, returning the file and an error, if any happens.
func (*PrefixFs) LchownIfPossible ¶ added in v0.6.0
func (*PrefixFs) LstatIfPossible ¶
LstatIfPossible will call Lstat if the filesystem itself is, or it delegates to, the os filesystem. Else it will call Stat. In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not.
func (*PrefixFs) Mkdir ¶
Mkdir creates a directory in the filesystem, return an error if any happens.
func (*PrefixFs) MkdirAll ¶
MkdirAll creates a directory path and all parents that does not exist yet.
func (*PrefixFs) Open ¶
Open opens a file, returning it or an error, if any happens. This returns a ready only file
func (*PrefixFs) ReadlinkIfPossible ¶ added in v0.4.0
func (*PrefixFs) Remove ¶
Remove removes a file identified by name, returning an error, if any happens.
func (*PrefixFs) RemoveAll ¶
RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).
func (*PrefixFs) Stat ¶
Stat returns a FileInfo describing the named file, or an error, if any happens.
func (*PrefixFs) SymlinkIfPossible ¶ added in v0.4.0
SymlinkIfPossible changes the access and modification times of the named file
type VolumeFs ¶ added in v0.9.0
type VolumeFs struct {
// contains filtered or unexported fields
}
VolumeFs is specifically designed to prefix absolute paths with a defined volume like C:, D:, E: etc. We want to be able to decide which volume to target on Windows operating systems.
func (*VolumeFs) Chtimes ¶ added in v0.9.0
Chtimes changes the access and modification times of the named file
func (*VolumeFs) Create ¶ added in v0.9.0
Create creates a file in the filesystem, returning the file and an error, if any happens.
func (*VolumeFs) LchownIfPossible ¶ added in v0.9.0
func (*VolumeFs) LstatIfPossible ¶ added in v0.9.0
LstatIfPossible will call Lstat if the filesystem itself is, or it delegates to, the os filesystem. Else it will call Stat. In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not.
func (*VolumeFs) Mkdir ¶ added in v0.9.0
Mkdir creates a directory in the filesystem, return an error if any happens.
func (*VolumeFs) MkdirAll ¶ added in v0.9.0
MkdirAll creates a directory path and all parents that does not exist yet.
func (*VolumeFs) Open ¶ added in v0.9.0
Open opens a file, returning it or an error, if any happens. This returns a ready only file
func (*VolumeFs) OpenFile ¶ added in v0.9.0
OpenFile opens a file using the given flags and the given mode.
func (*VolumeFs) ReadlinkIfPossible ¶ added in v0.9.0
func (*VolumeFs) Remove ¶ added in v0.9.0
Remove removes a file identified by name, returning an error, if any happens.
func (*VolumeFs) RemoveAll ¶ added in v0.9.0
RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).
func (*VolumeFs) Stat ¶ added in v0.9.0
Stat returns a FileInfo describing the named file, or an error, if any happens.
func (*VolumeFs) SymlinkIfPossible ¶ added in v0.9.0
SymlinkIfPossible changes the access and modification times of the named file