Documentation ¶
Index ¶
- Constants
- Variables
- func CompareFile(buffer []byte, filename string) (bool, error)
- func CompareFiles(leftFilename, rightFilename string) (bool, error)
- func CopyFile(destFilename, sourceFilename string, mode os.FileMode) error
- func CopyToFile(destFilename string, perm os.FileMode, reader io.Reader, length uint64) error
- func CopyTree(destDir, sourceDir string) error
- func CopyTreeWithCopyFunc(destDir, sourceDir string, ...) error
- func Fallocate(filename string, size uint64) error
- func ForceLink(oldname, newname string) error
- func ForceRemove(name string) error
- func ForceRemoveAll(path string) error
- func ForceRename(oldpath, newpath string) error
- func FsyncFile(file *os.File) error
- func GetTreeSize(dirname string) (uint64, error)
- func LoadLines(filename string) ([]string, error)
- func LoopbackDelete(loopDevice string) error
- func LoopbackSetup(filename string) (string, error)
- func MakeMutable(pathname ...string) error
- func ReadDirnames(dirname string, ignoreMissing bool) ([]string, error)
- func ReadLines(reader io.Reader) ([]string, error)
- func UpdateFile(buffer []byte, filename string) (bool, error)
- func WaitFile(pathname string, timeout time.Duration) (io.ReadCloser, error)
- func WatchFile(pathname string, logger log.Logger) <-chan io.ReadCloser
- func WatchFileStop()
- type ChecksumReader
- type ChecksumWriter
- type RenamingWriter
Constants ¶
Variables ¶
var (
ErrorChecksumMismatch = errors.New("checksum mismatch")
)
Functions ¶
func CompareFile ¶
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 ¶
CompareFiles will read and compare the content of two files and return true if they are the same else false.
func CopyToFile ¶
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 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 ¶
Fallocate will allocate blocks for the file named filename, up to size specified in bytes.
func ForceLink ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
GetTreeSize will walk a directory tree and count the size of the files.
func LoadLines ¶
LoadLines will open a file and read lines from it. Comment lines (i.e. lines beginning with '#') are skipped.
func LoopbackDelete ¶
LoopbackDelete will disassociate (delete) a loopback block device from its backing file. The name of the block device is returned.
func LoopbackSetup ¶
LoopbackSetup will associate a loopback block device with a regular file named filename. The name of the block device is returned.
func MakeMutable ¶
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 ¶
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 ¶
ReadLines will read lines from a reader. Comment lines (i.e. lines beginning with '#') are skipped.
func UpdateFile ¶
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 ¶
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) 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) WriteChecksum ¶
func (w *ChecksumWriter) WriteChecksum() error
type RenamingWriter ¶
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.