fileutil

package
v4.0.0-...-1d6e2d7 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFileMode is the default file mode for files generated by
	// Dragonboat.
	DefaultFileMode = 0640
	// SnapshotFlagFilename defines the filename of the snapshot flag file.
	SnapshotFlagFilename = "dragonboat.snapshot.message"
)

Variables

View Source
var Discard = io.Discard

Discard ...

Functions

func CreateFlagFile

func CreateFlagFile(dir string,
	filename string, msg pb.Marshaler, fs vfs.IFS) (err error)

CreateFlagFile creates a flag file in the specific location. The flag file contains the marshaled data of the specified protobuf message.

CreateFlagFile is not atomic meaning you can end up having a file at fs.PathJoin(dir, filename) with partial or corrupted content when the machine crashes in the middle of this function call. Special care must be taken to handle such situation, see how CreateFlagFile is used by snapshot images as an example.

func CreateTemp

func CreateTemp(dir string, pattern string) (*os.File, error)

CreateTemp ...

func DirExist

func DirExist(name string, fs vfs.IFS) (result bool, err error)

DirExist returns whether the specified filesystem entry exists.

func Exist

func Exist(name string, fs vfs.IFS) (bool, error)

Exist returns whether the specified filesystem entry exists.

func ExtractTarBz2

func ExtractTarBz2(bz2fn string, toDir string, fs vfs.IFS) (err error)

ExtractTarBz2 extracts files and directories from the specified tar.bz2 file to the specified target directory.

func GetFlagFileContent

func GetFlagFileContent(dir string,
	filename string, msg pb.Unmarshaler, fs vfs.IFS) (err error)

GetFlagFileContent gets the content of the flag file found in the specified location. The data of the flag file will be unmarshaled into the specified protobuf message.

func HasFlagFile

func HasFlagFile(dir string, filename string, fs vfs.IFS) bool

HasFlagFile returns a boolean value indicating whether flag file can be found in the specified location.

func IsDirMarkedAsDeleted

func IsDirMarkedAsDeleted(dir string, fs vfs.IFS) (bool, error)

IsDirMarkedAsDeleted returns a boolean flag indicating whether the specified directory has been marked as deleted.

func MarkDirAsDeleted

func MarkDirAsDeleted(dir string, msg pb.Marshaler, fs vfs.IFS) error

MarkDirAsDeleted marks the specified directory as deleted.

func Mkdir

func Mkdir(dir string, fs vfs.IFS) error

Mkdir creates the specified dir.

func MkdirAll

func MkdirAll(dir string, fs vfs.IFS) error

MkdirAll creates the specified dir along with any necessary parents.

func MkdirTemp

func MkdirTemp(dir string, pattern string) (string, error)

MkdirTemp ...

func MustWrite

func MustWrite(w io.Writer, data []byte)

MustWrite writes the specified data to the input writer. It will panic if there is any error.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll ...

func ReadFile

func ReadFile(name string) ([]byte, error)

ReadFile ...

func RemoveFlagFile

func RemoveFlagFile(dir string, filename string, fs vfs.IFS) error

RemoveFlagFile removes the specified flag file.

func SyncDir

func SyncDir(dir string, fs vfs.IFS) (err error)

SyncDir calls fsync on the specified directory.

func TempDir

func TempDir(dir, pattern string, fs vfs.IFS) (name string, err error)

TempDir creates a new temporary directory in the directory dir. The directory name is generated by taking pattern and applying a random string to the end. If pattern includes a "*", the random string replaces the last "*". TempDir returns the name of the new directory. If dir is the empty string, TempDir uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempDir simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when no longer needed.

func TempFile

func TempFile(dir,
	pattern string, fs vfs.IFS) (f vfs.File, name string, err error)

TempFile returns a temp file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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