backupfs

package module
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 16 Imported by: 0

README

BackupFs

Multiple filesystem abstraction layers working together to create a straight forward rollback mechanism for filesystem modifications with OS-independent file paths. This package provides multiple filesystem abstractions which implement the spf13/afero.Fs interface as well as the optional interfaces.

They require the filesystem modifications to happen via the provided structs of this package.

Example Use Case

My own use case is the ability to implement the command pattern on top of a filesystem. The pattern consists of a simple interface.

type Command interface {
	Do() error
	Undo() error
}

A multitude of such commands allows to provision software packages (archives) and configuration files to target systems running some kind of agent software. Upon detection of invalid configurations or incorrect software, it is possible to rollback the last transaction.

A transaction is also a command containing a list of non-transaction commands embedding and providing a BackupFs to its subcommands requiring to execute filesystem operations.

For all commands solely operating on the filesystem the Undo() mechanism consists of simply calling BackupFs.Rollback()

Further commands might tackle the topics of:

  • un/tar
  • creation of files, directories & symlinks
  • removal of files, directories & symlinks
  • download of files and writing them to the filesystem
  • rotation of persisted credentials that might not work upon testing

If you try to tackle the rollback/undo problem yourself you will see pretty fast that the rollback mechanism is a pretty complex implementation with lots of pitfalls where this approach might help you out.

If you follow the rule that filesystem modifying commands

  • creation,
  • deletion
  • or modification of files, directories and symlinks
  • creation of systemd unit files (writing service configuration)

are to be strictly separated from side effects causing commands

  • creation of linux system users and groups
  • start of linux systemd services configured with the above file in the filesystem

then you will have a much easier time!

VolumeFs

VolumeFs is a filesystem abstraction layer that hides Windows volumes from file system operations. It allows to define a volume of operation like c: or C: which is then the only volume that can be accessed. This abstraction layer allows to operate on filesystems with operating system independent paths.

PrefixFs

PrefixFs forces a filesystem to have a specific prefix. Any attempt to escape the prefix path by directory traversal is prevented, forcing the application to stay within the designated prefix directory. This prefix makes the directory basically the application's root directory.

BackupFs

The most important part of this library is BackupFs. It is a filesystem abstraction that consists of two parts. A base filesystem and a backup filesystem. Any attempt to modify a file, directory or symlink in the base filesystem leads to the file being backed up to the backup filesystem.

Consecutive file modifications are ignored, as the initial file state has already been backed up.

HiddenFs

HiddenFs has a single purpose, that is to hide your backup location and prevent your application from seeing or modifying it. In case you use BackupFs to backup files that are overwritten on your operating system filesystem (OsFs), you want to define multiple filesystem layers that work together to prevent you from creating a non-terminating recursion of file backups.

  • The zero'th layer is the underlying real filesystem, be it the OsFs, MemMapFs, etc.
  • The first layer is a VolumeFs filesystem abstraction that removes the need to provide a volume prefix for absolute file paths when accessing files on the underlying filesystem (Windows)
  • The second layer is a PrefixFs that is provided a prefix path (backup directory location) and the above instantiated filesystem (e.g. OsFs)
  • The third layer is HiddenFs which takes the backup location as path that needs hiding and wraps the first layer in itself.
  • The fourth layer is the BackupFs layer which takes the third layer as underlying filesystem to operate on (backup location is not accessible nor viewable) and the second PrefixFs layer to backup your files to.

At the end you will create something along the lines of:

package main

import (
	"os"
	"path/filepath"

	"github.com/jxsl13/backupfs"
	"github.com/spf13/afero"
)

func main() {

	var (
		// first layer: abstracts away the volume prefix (on Unix the it is an empty string)
		volume     = filepath.VolumeName(os.Args[0]) // determined from application path
		base       = backupfs.NewVolumeFs(volume, afero.NewMemMapFs())
		backupPath = "/var/opt/app/backups"

		// second layer: abstracts away a path prefix
		backup = backupfs.NewPrefixFs(backupPath, base)

		// third layer: hides the backup location in order to prevent recursion
		masked = backupfs.NewHiddenFs(backupPath, base)

		// fourth layer: backup on write filesystem with rollback
		backupFs = backupfs.NewBackupFs(masked, backup)
	)
	// you may use backupFs at this point like the os package
	// except for the backupFs.Rollback() machanism which
	// allows you to rollback filesystem modifications.
}

Example

We create a base filesystem with an initial file in it. Then we define a backup filesystem as subdirectory of the base filesystem.

Then we do wrap the base filesystem and the backup filesystem in the BackupFs wrapper and try modifying the file through the BackupFs file system layer which has initiall ybeen created in the base filesystem. So BackupFs tries to modify an already existing file leading to it being backedup. A call to BackupFs.Rollback() allows to rollback the filesystem modifications done with BackupFs back to its original state while also deleting the backup.

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/jxsl13/backupfs"
	"github.com/spf13/afero"
)

func checkErr(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func main() {

	var (
		// base filesystem
		baseFs   = afero.NewMemMapFs()
		filePath = "/var/opt/test.txt"
	)

	// create an already existing file in base filesystem
	f, err := baseFs.Create(filePath)
	checkErr(err)

	f.WriteString("original text")
	f.Close()

	// at this point we have the base filesystem ready to be ovwerwritten with new files
	var (
		// sub directory in base filesystem as backup directory
		// where the backups should be stored
		backup = backupfs.NewPrefixFs("/var/opt/application/backup", baseFs)

		// backup on write filesystem
		backupFs = backupfs.NewBackupFs(baseFs, backup)
	)

	// we try to override a file in the base filesystem
	f, err = backupFs.Create(filePath)
	checkErr(err)
	f.WriteString("new file content")
	f.Close()

	// before we overwrite the file a backup was created
	// at the same path as the overwritten file was found at.
	// due to our backup being on a prefixedfilesystem, we can find
	// the backedup file at a prefixed location

	f, err = backup.Open(filePath)
	checkErr(err)

	b, err := io.ReadAll(f)
	checkErr(err)
	f.Close()

	backedupContent := string(b)

	f, err = baseFs.Open(filePath)
	checkErr(err)
	b, err = io.ReadAll(f)
	checkErr(err)

	overwrittenFileContent := string(b)

	fmt.Println("Overwritten file: ", overwrittenFileContent)
	fmt.Println("Backed up file  : ", backedupContent)

	afs := afero.Afero{Fs: backupFs}
	fi, err := afs.ReadDir("/var/opt/")
	checkErr(err)

	for _, f := range fi {
		fmt.Println("Found name: ", f.Name())
	}

}

TODO

  • Add symlink fuzz tests on os filesystem that deletes the symlink after each test.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)
)
View Source
var (
	ErrHiddenNotExist   = fmt.Errorf("hidden: %w", os.ErrNotExist)
	ErrHiddenPermission = fmt.Errorf("hidden: %w", os.ErrPermission)
)

Functions

func TrimVolume added in v0.9.0

func TrimVolume(filePath string) string

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

func NewBackupFs(base, backup afero.Fs) *BackupFs

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

func NewBackupFsWithVolume(base, backup afero.Fs) *BackupFs

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) Chmod

func (fs *BackupFs) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*BackupFs) Chown

func (fs *BackupFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*BackupFs) Chtimes

func (fs *BackupFs) Chtimes(name string, atime, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*BackupFs) Create

func (fs *BackupFs) Create(name string) (File, error)

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 (fs *BackupFs) ForceBackup(name string) (err error)

func (*BackupFs) GetBackupFs added in v0.4.7

func (fs *BackupFs) GetBackupFs() afero.Fs

GetBackupFs returns the fs layer that is used to store the backups

func (*BackupFs) GetBaseFs added in v0.4.7

func (fs *BackupFs) GetBaseFs() afero.Fs

GetBaseFs returns the fs layer that is being written to

func (*BackupFs) LchownIfPossible added in v0.6.0

func (fs *BackupFs) LchownIfPossible(name string, uid, gid int) error

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 (fs *BackupFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*BackupFs) Map added in v0.7.5

func (fs *BackupFs) Map() map[string]os.FileInfo

func (*BackupFs) MarshalJSON added in v0.2.0

func (fs *BackupFs) MarshalJSON() ([]byte, error)

func (*BackupFs) Mkdir

func (fs *BackupFs) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*BackupFs) MkdirAll

func (fs *BackupFs) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*BackupFs) Name

func (fs *BackupFs) Name() string

The name of this FileSystem

func (*BackupFs) Open

func (fs *BackupFs) Open(name string) (File, error)

Open opens a file, returning it or an error, if any happens. This returns a ready only file

func (*BackupFs) OpenFile

func (fs *BackupFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile opens a file using the given flags and the given mode.

func (*BackupFs) ReadlinkIfPossible added in v0.4.0

func (fs *BackupFs) ReadlinkIfPossible(name string) (string, error)

func (*BackupFs) Remove

func (fs *BackupFs) Remove(name string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*BackupFs) RemoveAll

func (fs *BackupFs) RemoveAll(name string) error

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) Rename

func (fs *BackupFs) Rename(oldname, newname string) error

Rename renames a file.

func (*BackupFs) Rollback added in v0.2.0

func (fs *BackupFs) Rollback() error

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

func (fs *BackupFs) Stat(name string) (os.FileInfo, error)

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

func (fs *BackupFs) SymlinkIfPossible(oldname, newname string) error

SymlinkIfPossible changes the access and modification times of the named file

func (*BackupFs) UnmarshalJSON added in v0.2.0

func (fs *BackupFs) UnmarshalJSON(data []byte) error

type File

type File = afero.File

File is implemented by the imported directory.

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

func NewHiddenFs(base afero.Fs, hiddenPaths ...string) *HiddenFs

NewHiddenFs hides away anthing beneath the specified paths.

func (*HiddenFs) Chmod added in v0.7.1

func (s *HiddenFs) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*HiddenFs) Chown added in v0.7.1

func (s *HiddenFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*HiddenFs) Chtimes added in v0.7.1

func (s *HiddenFs) Chtimes(name string, atime, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*HiddenFs) Create added in v0.7.1

func (s *HiddenFs) Create(name string) (File, error)

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 (s *HiddenFs) LchownIfPossible(name string, uid, gid int) error

func (*HiddenFs) LstatIfPossible added in v0.7.1

func (s *HiddenFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

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

func (s *HiddenFs) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*HiddenFs) MkdirAll added in v0.7.1

func (s *HiddenFs) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*HiddenFs) Name added in v0.7.1

func (s *HiddenFs) Name() string

The name of this FileSystem

func (*HiddenFs) Open added in v0.7.1

func (s *HiddenFs) Open(name string) (File, error)

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

func (s *HiddenFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile opens a file using the given flags and the given mode.

func (*HiddenFs) ReadlinkIfPossible added in v0.7.1

func (s *HiddenFs) ReadlinkIfPossible(name string) (string, error)

func (*HiddenFs) Remove added in v0.7.1

func (s *HiddenFs) Remove(name string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*HiddenFs) RemoveAll added in v0.7.1

func (s *HiddenFs) RemoveAll(name string) error

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*HiddenFs) Rename added in v0.7.1

func (s *HiddenFs) Rename(oldname, newname string) error

Rename renames a file.

func (*HiddenFs) Stat added in v0.7.1

func (s *HiddenFs) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (*HiddenFs) SymlinkIfPossible added in v0.7.1

func (s *HiddenFs) SymlinkIfPossible(oldname, newname string) error

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) Stat added in v0.7.1

func (hf *HiddenFsFile) Stat() (os.FileInfo, 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

type LinkOwner interface {
	LchownIfPossible(name string, uid int, gid int) error
}

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) Read

func (pf *PrefixFile) Read(p []byte) (n int, err error)

func (*PrefixFile) ReadAt

func (pf *PrefixFile) ReadAt(p []byte, off int64) (n int, err error)

func (*PrefixFile) Readdir

func (pf *PrefixFile) Readdir(count int) ([]os.FileInfo, error)

func (*PrefixFile) Readdirnames

func (pf *PrefixFile) Readdirnames(n int) ([]string, error)

func (*PrefixFile) Seek

func (pf *PrefixFile) Seek(offset int64, whence int) (int64, error)

func (*PrefixFile) Stat

func (pf *PrefixFile) Stat() (os.FileInfo, error)

func (*PrefixFile) Sync

func (pf *PrefixFile) Sync() error

func (*PrefixFile) Truncate

func (pf *PrefixFile) Truncate(size int64) error

func (*PrefixFile) Write

func (pf *PrefixFile) Write(p []byte) (n int, err error)

func (*PrefixFile) WriteAt

func (pf *PrefixFile) WriteAt(p []byte, off int64) (n int, err 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

func NewPrefixFs(prefixPath string, fs afero.Fs) *PrefixFs

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) Chmod

func (s *PrefixFs) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*PrefixFs) Chown

func (s *PrefixFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*PrefixFs) Chtimes

func (s *PrefixFs) Chtimes(name string, atime, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*PrefixFs) Create

func (s *PrefixFs) Create(name string) (File, error)

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 (s *PrefixFs) LchownIfPossible(name string, uid, gid int) error

func (*PrefixFs) LstatIfPossible

func (s *PrefixFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

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

func (s *PrefixFs) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*PrefixFs) MkdirAll

func (s *PrefixFs) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*PrefixFs) Name

func (s *PrefixFs) Name() string

The name of this FileSystem

func (*PrefixFs) Open

func (s *PrefixFs) Open(name string) (File, error)

Open opens a file, returning it or an error, if any happens. This returns a ready only file

func (*PrefixFs) OpenFile

func (s *PrefixFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile opens a file using the given flags and the given mode.

func (*PrefixFs) ReadlinkIfPossible added in v0.4.0

func (s *PrefixFs) ReadlinkIfPossible(name string) (string, error)

func (*PrefixFs) Remove

func (s *PrefixFs) Remove(name string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*PrefixFs) RemoveAll

func (s *PrefixFs) RemoveAll(name string) error

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*PrefixFs) Rename

func (s *PrefixFs) Rename(oldname, newname string) error

Rename renames a file.

func (*PrefixFs) Stat

func (s *PrefixFs) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (*PrefixFs) SymlinkIfPossible added in v0.4.0

func (s *PrefixFs) SymlinkIfPossible(oldname, newname string) error

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 NewVolumeFs added in v0.9.0

func NewVolumeFs(volume string, fs afero.Fs) *VolumeFs

func (*VolumeFs) Chmod added in v0.9.0

func (v *VolumeFs) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*VolumeFs) Chown added in v0.9.0

func (v *VolumeFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*VolumeFs) Chtimes added in v0.9.0

func (v *VolumeFs) Chtimes(name string, atime, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*VolumeFs) Create added in v0.9.0

func (v *VolumeFs) Create(name string) (File, error)

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 (v *VolumeFs) LchownIfPossible(name string, uid, gid int) error

func (*VolumeFs) LstatIfPossible added in v0.9.0

func (v *VolumeFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

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

func (v *VolumeFs) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*VolumeFs) MkdirAll added in v0.9.0

func (v *VolumeFs) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*VolumeFs) Name added in v0.9.0

func (v *VolumeFs) Name() string

The name of this FileSystem

func (*VolumeFs) Open added in v0.9.0

func (v *VolumeFs) Open(name string) (File, error)

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

func (v *VolumeFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile opens a file using the given flags and the given mode.

func (*VolumeFs) ReadlinkIfPossible added in v0.9.0

func (v *VolumeFs) ReadlinkIfPossible(name string) (string, error)

func (*VolumeFs) Remove added in v0.9.0

func (v *VolumeFs) Remove(name string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*VolumeFs) RemoveAll added in v0.9.0

func (v *VolumeFs) RemoveAll(name string) error

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*VolumeFs) Rename added in v0.9.0

func (v *VolumeFs) Rename(oldname, newname string) error

Rename renames a file.

func (*VolumeFs) Stat added in v0.9.0

func (v *VolumeFs) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (*VolumeFs) SymlinkIfPossible added in v0.9.0

func (v *VolumeFs) SymlinkIfPossible(oldname, newname string) error

SymlinkIfPossible changes the access and modification times of the named file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL