fs

package
v0.0.0-...-81c1a03 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHostIsEmpty = errors.New("host must be non-empty")

Functions

func IsExist

func IsExist(err error) bool

IsExist is like os.IsExist, but also handles non-local file systems.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist is like os.IsNotExist, but also handles non-local file systems.

func IsPermission

func IsPermission(err error) bool

IsPermission is like os.IsPermission, but also handles non-local file systems.

Types

type COW

type COW struct {
	// contains filtered or unexported fields
}

COW is a per-host, timestamped, copy-on-write file system. Its Keep function hardlinks a file from the latest time of the same host, if it exists. Otherwise it takes the latest time of any host.

On Finish, the file system writes a "<host>/<time>.complete" file and updates the ".latest" symlinks.

func NewCOW

func NewCOW(fs WriteableFileSystem, host string, t time.Time) (*COW, error)

NewCOW returns a new copy-on-write file system at the given location, for a given hostname and timestamp. The time directory must not exist, and the timestamp must be later than what the ".latest" file points to.

func (*COW) Chmod

func (fs *COW) Chmod(path Path, mode os.FileMode) error

func (*COW) Chtimes

func (fs *COW) Chtimes(path Path, atime time.Time, mtime time.Time) error

func (*COW) Create

func (fs *COW) Create(path Path) (FileWriter, error)

func (*COW) Finish

func (fs *COW) Finish() error

func (*COW) Keep

func (fs *COW) Keep(path Path) error

func (*COW) Lchown

func (fs *COW) Lchown(path Path, uid, gid int) error
func (fs *COW) Link(oldpath Path, newpath Path) error

func (*COW) Mkdir

func (fs *COW) Mkdir(path Path, mode os.FileMode, uid, gid int) error

func (*COW) Open

func (fs *COW) Open(path Path) (FileReader, error)
func (fs *COW) Readlink(path Path) (Path, error)

func (*COW) Remove

func (fs *COW) Remove(path Path) error

func (*COW) RemoveAll

func (fs *COW) RemoveAll(path Path) error

func (*COW) Rename

func (fs *COW) Rename(oldpath Path, newpath Path) error

func (*COW) Stat

func (fs *COW) Stat() (FSInfo, error)
func (fs *COW) Symlink(oldpath Path, newpath Path) error

type FSInfo

type FSInfo struct {
	// FreeSpace describes how many bytes are available for use.
	FreeSpace uint64
}

FSInfo carries statistics about a file system.

type FileAttrs

type FileAttrs struct {
	UID        int
	GID        int
	AccessTime time.Time
	NLinks     uint64
	Inode      uint64
}

func FileAttrsFromFileInfo

func FileAttrsFromFileInfo(fi os.FileInfo) (FileAttrs, bool)

FileAttrsFromFileInfo extracts system-specific file attributes from a FileInfo.

type FileReader

type FileReader interface {
	io.Reader
	io.Closer

	// Readdir returns all directory entries, if the file represents a directory.
	Readdir() ([]os.FileInfo, error)

	// Stat returns metadata about the file.
	Stat() (os.FileInfo, error)
}

A FileReader represents an open file stream or directory that can be read from.

type FileWriter

type FileWriter interface {
	io.Writer
	io.Closer

	// Chmod changes file modes and permissions.
	Chmod(os.FileMode) error

	// Lchown changes the owner or group of the file.
	// If uid or gid are -1, that value is ignored.
	Chown(uid, gid int) error
}

A FileWriter represents an open file stream that can be written to.

type Local

type Local struct {
	// contains filtered or unexported fields
}

Local is a file system working on the OS native file system.

func NewLocal

func NewLocal(root string) *Local

NewLocal constructs a new object to access the OS native file system.

func (*Local) Chmod

func (fs *Local) Chmod(path Path, mode os.FileMode) error

Chmod changes file or directory modes and permissions.

func (*Local) Chtimes

func (fs *Local) Chtimes(path Path, atime time.Time, mtime time.Time) error

Chtimes modifies the file or directory metadata for access and modification times.

func (*Local) Create

func (fs *Local) Create(path Path) (FileWriter, error)

Create creates (or overwrites) a file and opens it for writing.

func (*Local) Keep

func (fs *Local) Keep(path Path) error

Keep informs the file system that the file should be kept. This does nothing.

func (*Local) Lchown

func (fs *Local) Lchown(path Path, uid, gid int) error

Lchown changes the owner or group of a file or directory. If uid or gid are -1, that value is ignored. Symlinks are updated, not followed.

func (fs *Local) Link(oldpath Path, newpath Path) error

Link creates a hardlink to an existing file.

func (*Local) Mkdir

func (fs *Local) Mkdir(path Path, mode os.FileMode, uid, gid int) error

Mkdir creates a new directory. If uid or gid are -1, that value is ignored.

func (*Local) Open

func (fs *Local) Open(path Path) (FileReader, error)

Open opens a file or directory for reading.

func (fs *Local) Readlink(path Path) (Path, error)

Readlink returns the contents of the given symlink.

func (*Local) Remove

func (fs *Local) Remove(path Path) error

Remove deletes a file or empty directory.

func (*Local) RemoveAll

func (fs *Local) RemoveAll(path Path) error

RemoveAll recursively deletes a directory (or file).

func (*Local) Rename

func (fs *Local) Rename(oldpath Path, newpath Path) error

Rename moves a file or directory from one path to another.

func (*Local) Stat

func (fs *Local) Stat() (FSInfo, error)

Stat returns information about this file system.

func (fs *Local) Symlink(oldpath Path, newpath Path) error

Symlink creates a symlink pointing to a file or directory.

type Path

type Path string

A Path points to a file or directory within a file system. They are always relative the root of the file system and never starts with a directory separator.

func (Path) Base

func (p Path) Base() Path

Base returns the last component of the path.

func (Path) Dir

func (p Path) Dir() Path

Dir returns all but the last component of the path.

func (Path) Resolve

func (p Path) Resolve(pp Path) Path

Resolve looks up "pp" in the context of "p".

type ReadableFileSystem

type ReadableFileSystem interface {
	// Open opens a file or directory for reading.
	Open(path Path) (FileReader, error)

	// Readlink returns the contents of the given symlink.
	Readlink(path Path) (Path, error)

	// Stat returns information about this file system.
	Stat() (FSInfo, error)
}

A ReadableFileSystem can only be read from.

type SFTP

type SFTP struct {
	// contains filtered or unexported fields
}

An SFTP uses SFTP to read and write files. It doesn't do retries, and should be used together with remote.ReconnectingSFTPClient and remote.Idempotent.

func NewSFTP

func NewSFTP(client remote.SFTPClient, root Path) *SFTP

NewSFTP creates a new file system at the given root path.

func (*SFTP) Chmod

func (fs *SFTP) Chmod(path Path, mode os.FileMode) error

func (*SFTP) Chtimes

func (fs *SFTP) Chtimes(path Path, atime time.Time, mtime time.Time) error

func (*SFTP) Create

func (fs *SFTP) Create(path Path) (FileWriter, error)

func (*SFTP) Keep

func (fs *SFTP) Keep(path Path) error

func (*SFTP) Lchown

func (fs *SFTP) Lchown(path Path, uid, gid int) error
func (fs *SFTP) Link(oldpath Path, newpath Path) error

func (*SFTP) Mkdir

func (fs *SFTP) Mkdir(path Path, mode os.FileMode, uid, gid int) error

func (*SFTP) Open

func (fs *SFTP) Open(path Path) (FileReader, error)
func (fs *SFTP) Readlink(path Path) (Path, error)

func (*SFTP) Remove

func (fs *SFTP) Remove(path Path) error

func (*SFTP) RemoveAll

func (fs *SFTP) RemoveAll(path Path) error

func (*SFTP) Rename

func (fs *SFTP) Rename(oldpath Path, newpath Path) error

func (*SFTP) Stat

func (fs *SFTP) Stat() (FSInfo, error)
func (fs *SFTP) Symlink(oldpath Path, newpath Path) error

type WriteableFileSystem

type WriteableFileSystem interface {
	ReadableFileSystem

	// Create creates (or overwrites) a file and opens it for writing.
	Create(path Path) (FileWriter, error)

	// Keep informs the file system that the file should be kept.
	Keep(path Path) error

	// Mkdir creates a new directory. If uid or gid are -1, that value is ignored.
	Mkdir(path Path, mode os.FileMode, uid, gid int) error

	// Link creates a hardlink to an existing file.
	Link(oldpath Path, newpath Path) error

	// Symlink creates a symlink pointing to a file or directory.
	Symlink(oldpath Path, newpath Path) error

	// Rename moves a file or directory from one path to another.
	Rename(oldpath Path, newpath Path) error

	// RemoveAll recursively deletes a directory (or file).
	RemoveAll(path Path) error

	// Remove deletes a file or empty directory.
	Remove(path Path) error

	// Chmod changes file or directory modes and permissions.
	Chmod(Path, os.FileMode) error

	// Lchown changes the owner or group of a file or directory.
	// If uid or gid are -1, that value is ignored. Symlinks are updated, not followed.
	Lchown(path Path, uid, gid int) error

	// Chtimes modifies the file or directory metadata for access and modification times.
	Chtimes(path Path, atime time.Time, mtime time.Time) error
}

A WriteableFileSystem can be both used to both read and write files.

Jump to

Keyboard shortcuts

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