fsutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 142

Documentation

Index

Constants

Variables

View Source
var (
	ErrorChecksumMismatch = errors.New("checksum mismatch")
)

Functions

func CompareFile

func CompareFile(buffer []byte, filename string) (bool, error)

CompareFile will read and compare the content of a file and buffer and will return true if the contents are the same else false.

func CompareFiles

func CompareFiles(leftFilename, rightFilename string) (bool, error)

CompareFiles will read and compare the content of two files and return true if they are the same else false.

func CopyFile

func CopyFile(destFilename, sourceFilename string, mode os.FileMode) error

func CopyToFile

func CopyToFile(destFilename string, perm os.FileMode, reader io.Reader,
	length uint64) error

CopyToFile will create a new file, write length bytes from reader to the file and then atomically renames the file to destFilename. If length is zero all remaining bytes from reader are written. If there are any errors, then destFilename is unchanged.

func CopyTree

func CopyTree(destDir, sourceDir string) error

CopyTree will copy a directory tree.

func CopyTreeWithCopyFunc

func CopyTreeWithCopyFunc(destDir, sourceDir string,
	copyFunc func(destFilename, sourceFilename string,
		mode os.FileMode) error) error

CopyTreeWithCopyFunc is similar to CopyTree except it uses a specified copy function for copying regular files.

func Fallocate

func Fallocate(filename string, size uint64) error

Fallocate will allocate blocks for the file named filename, up to size specified in bytes.

func ForceLink(oldname, newname string) error

ForceLink creates newname as a hard link to the oldname file. It first attempts to link using os.Link. If the first attempt fails due to a permission error, it blindly calls MakeMutable and then retries. If the first attempt fails due to newname existing, it blindly removes it and then retries.

func ForceRemove

func ForceRemove(name string) error

ForceRemove removes the named file or directory. It first attempts to remove using os.Remove and that fails, it blindly calls MakeMutable and then retries.

func ForceRemoveAll

func ForceRemoveAll(path string) error

ForceRemoveAll removes path and any children it contains. It first attempts to remove using os.RemoveAll and that fails, it blindly calls MakeMutable and then retries.

func ForceRename

func ForceRename(oldpath, newpath string) error

ForceRename renames (moves) a file. It first attempts to rename using os.Rename and if that fails due to a permission error, it blindly calls MakeMutable and then retries. If it fails because newpath is a directory, it calls ForceRemoveAll(newpath) and tries again.

func FsyncFile

func FsyncFile(file *os.File) error

FsyncFile will call file.Sync if it has not been called recently. This attempts to reduce the performance problems of fsync(2) by potentially sacrificing some file-system consistency.

func GetTreeSize added in v0.3.2

func GetTreeSize(dirname string) (uint64, error)

GetTreeSize will walk a directory tree and count the size of the files.

func LoadLines

func LoadLines(filename string) ([]string, error)

LoadLines will open a file and read lines from it. Comment lines (i.e. lines beginning with '#') are skipped.

func LoopbackDelete

func LoopbackDelete(loopDevice string) error

LoopbackDelete will disassociate (delete) a loopback block device from its backing file. The name of the block device is returned.

func LoopbackSetup

func LoopbackSetup(filename string) (string, error)

LoopbackSetup will associate a loopback block device with a regular file named filename. The name of the block device is returned.

func MakeMutable

func MakeMutable(pathname ...string) error

MakeMutable attempts to remove the "immutable" and "append-only" ext2 file-system attributes for one or more files. It is equivalent to calling the command-line programme "chattr -ai pathname...".

func ReadDirnames

func ReadDirnames(dirname string, ignoreMissing bool) ([]string, error)

ReadDirnames will open the directory named dirname and will read the entries in that directory. If ignoreMissing is true, no error is returned if the directory does not exist.

func ReadLines

func ReadLines(reader io.Reader) ([]string, error)

ReadLines will read lines from a reader. Comment lines (i.e. lines beginning with '#') are skipped.

func UpdateFile

func UpdateFile(buffer []byte, filename string) (bool, error)

UpdateFile will read and compare the contents of a file and buffer and will update the file if different. It returns true if the contents were updated.

func WaitFile

func WaitFile(pathname string, timeout time.Duration) (io.ReadCloser, error)

WaitFile waits for the file given by pathname to become available to read and yields a io.ReadCloser when available, or an error if the timeout is exceeded or an error (other than file not existing) is encountered. A negative timeout indicates to wait forever. The io.ReadCloser must be closed after use.

func WatchFile

func WatchFile(pathname string, logger log.Logger) <-chan io.ReadCloser

WatchFile watches the file given by pathname and yields a new io.ReadCloser when a new inode is found and it is a regular file. The io.ReadCloser must be closed after use. Any errors are logged to the logger if it is not nil.

func WatchFileStop

func WatchFileStop()

WatchFileStop stops all file watching and cleans up resources that would otherwise persist across syscall.Exec.

Types

type ChecksumReader

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

func NewChecksumReader

func NewChecksumReader(reader io.Reader) *ChecksumReader

func (*ChecksumReader) GetChecksum

func (r *ChecksumReader) GetChecksum() []byte

func (*ChecksumReader) Read

func (r *ChecksumReader) Read(p []byte) (int, error)

func (*ChecksumReader) ReadByte

func (r *ChecksumReader) ReadByte() (byte, error)

func (*ChecksumReader) VerifyChecksum

func (r *ChecksumReader) VerifyChecksum() error

type ChecksumWriter

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

func NewChecksumWriter

func NewChecksumWriter(writer io.Writer) *ChecksumWriter

func (*ChecksumWriter) Write

func (w *ChecksumWriter) Write(p []byte) (int, error)

func (*ChecksumWriter) WriteChecksum

func (w *ChecksumWriter) WriteChecksum() error

type RenamingWriter

type RenamingWriter struct {
	*os.File
	// contains filtered or unexported fields
}

RenamingWriter is similar to a writable os.File, except that it attempts to ensure data integrity. A temporary file is used for writing, which is renamed during the Close method and an fsync(2) is attempted.

func CreateRenamingWriter

func CreateRenamingWriter(filename string, perm os.FileMode) (
	*RenamingWriter, error)

CreateRenamingWriter will create a temporary file for writing and will rename the temporary file to filename in the Close method if there are no write errors.

func (*RenamingWriter) Abort

func (w *RenamingWriter) Abort()

Abort will prevent file renaming during a subsequent Close method call.

func (*RenamingWriter) Close

func (w *RenamingWriter) Close() error

Close may attempt to fsync(2) the contents of the temporary file (if fsync(2) has not been called recently) and will then close and rename the temporary file if there were no Write errors or a call to the Abort method.

func (*RenamingWriter) Write

func (w *RenamingWriter) Write(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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