file

package
v0.0.0-...-be7858c Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package file implements the file tree interface (tree.Entry) for local filesystems.

Index

Constants

View Source
const (
	TEMPPREFIX = ".dtsync-"
	TEMPSUFFIX = ".tmp"
)

A prefix and suffix for files that are being copied.

Variables

This section is empty.

Functions

func Lchtimes

func Lchtimes(path string, atime time.Time, mtime time.Time) error

Lchtimes changes the ModTime of a file (like os.Chtimes) but does not follow symlinks.

Types

type Entry

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

Entry is one file or directory in the filesystem. It additionally contains it's name, parent, root, and stat() result.

func (*Entry) FullInfo

func (e *Entry) FullInfo() (tree.FileInfo, error)

FullInfo returns a tree.FileInfo with hash, or an error if the hash couldn't be calculated.

func (*Entry) HasMode

func (e *Entry) HasMode() tree.Mode

HasMode returns the permission bits this filesystem supports (at least 0777 for Unix-like filesystems).

func (*Entry) Hash

func (e *Entry) Hash() (tree.Hash, error)

Hash returns the blake2b hash of this file.

func (*Entry) Id

func (e *Entry) Id() (uint64, *tree.LocalFilesystem)

Id returns the inode and local filesystem information, if the underlying filesystem supports it.

func (*Entry) Info

func (e *Entry) Info() tree.FileInfo

Info returns a tree.FileInfo of the stat() result in this Entry (thus, without a hash).

func (*Entry) List

func (e *Entry) List(options tree.ListOptions) ([]tree.Entry, error)

List returns a directory listing, sorted by name.

func (*Entry) ModTime

func (e *Entry) ModTime() time.Time

ModTime returns the modification time from the (cached) stat() call.

func (*Entry) Mode

func (e *Entry) Mode() tree.Mode

Mode returns the mode bits for this file, as far as the filesystem supports them.

func (*Entry) Name

func (e *Entry) Name() string

Name returns the filename.

func (*Entry) RelativePath

func (e *Entry) RelativePath() []string

func (*Entry) Size

func (e *Entry) Size() int64

Size returns the filesize for regular files. For other file types, the result is undefined.

func (*Entry) String

func (e *Entry) String() string

String returns a string representation of this file, for debugging.

func (*Entry) Tree

func (e *Entry) Tree() tree.Tree

Tree returns the tree.Tree interface this Entry belongs to.

func (*Entry) Type

func (e *Entry) Type() tree.Type

Type returns the file type (regular, directory, or unknown). More types may be added in the future.

type Tree

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

Tree encapsulates the root path, so every Entry can know the root path.

func NewRoot

func NewRoot(rootPath string) (*Tree, error)

NewRoot wraps a root directory in an Entry.

func NewTestRoot

func NewTestRoot() (*Tree, error)

NewTestRoot returns a new root in a temporary directory. It should be removed after use using root.Remove()

func (*Tree) Chmod

func (r *Tree) Chmod(target, source tree.FileInfo) (tree.FileInfo, error)

Chmod applies the given mode bits and returns the stat() result. Not all bits may be applied (subject to HasMode()).

func (*Tree) Close

func (r *Tree) Close() error

Close does nothing: no files or directories are (currently) kept open.

func (*Tree) CopySource

func (r *Tree) CopySource(source tree.FileInfo) (io.ReadCloser, error)

func (*Tree) CreateDir

func (r *Tree) CreateDir(name string, parent, source tree.FileInfo) (tree.FileInfo, error)

CreateDir adds a single child directory.

func (*Tree) CreateFile

func (r *Tree) CreateFile(name string, parent, source tree.FileInfo) (tree.Copier, error)

CreateFile creates the child, implementing tree.FileEntry. This function is useful for Copy.

func (r *Tree) CreateSymlink(name string, parentInfo, sourceInfo tree.FileInfo, contents string) (tree.FileInfo, tree.FileInfo, error)

func (*Tree) GetFile

func (r *Tree) GetFile(name string) (io.ReadCloser, error)

GetFile returns an io.ReadCloser with the named file. The file must be closed after use.

func (*Tree) PutFile

func (r *Tree) PutFile(name string) (tree.Copier, error)

func (*Tree) PutFileTest

func (r *Tree) PutFileTest(path []string, contents []byte) (tree.FileInfo, error)

PutFileTest implements tree.TestTree by writing a single file with the given name and contents.

func (*Tree) ReadInfo

func (r *Tree) ReadInfo(path []string) (tree.FileInfo, error)

ReadInfo returns the FileInfo for the specified file with a hash.

func (r *Tree) ReadSymlink(file tree.FileInfo) (string, error)

func (*Tree) Remove

func (r *Tree) Remove(file tree.FileInfo) (tree.FileInfo, error)

Remove removes this entry, recursively. It returns the FileInfo of the parent, or an error.

func (*Tree) Root

func (r *Tree) Root() tree.Entry

func (*Tree) String

func (r *Tree) String() string

String returns a string representation of this root, for debugging.

func (*Tree) UpdateFile

func (r *Tree) UpdateFile(file, source tree.FileInfo) (tree.Copier, error)

UpdateFile replaces itself, to implement tree.FileEntry. This function is useful for Update.

func (*Tree) UpdateRsync

func (r *Tree) UpdateRsync(file, source tree.FileInfo) (tree.RsyncBasis, tree.Copier, error)

UpdateRsync opens the existing file to generate a signature for, and creates a new file where the new data is written, from the base file and from the patch data.

func (r *Tree) UpdateSymlink(file, source tree.FileInfo, contents string) (tree.FileInfo, tree.FileInfo, error)

Jump to

Keyboard shortcuts

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