fileutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFileMode is the default file mode for files generated.
	DefaultFileMode = 0640
)

Variables

This section is empty.

Functions

func CreateFlagFile

func CreateFlagFile(dir string,
	filename string, msg Marshaler, fs vfs.FS) (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 DirExist

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

DirExist returns whether the specified filesystem entry exists.

func Exist

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

Exist returns whether the specified filesystem entry exists.

func GetFlagFileContent

func GetFlagFileContent(dir string,
	filename string, obj Unmarshaler, fs vfs.FS) (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.FS) 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.FS) (bool, error)

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

func MarkDirAsDeleted

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

MarkDirAsDeleted marks the specified directory as deleted.

func Mkdir

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

Mkdir creates the specified dir.

func MkdirAll

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

MkdirAll creates the specified dir along with any necessary parents.

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 RemoveFlagFile

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

RemoveFlagFile removes the specified flag file.

func SyncDir

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

SyncDir calls fsync on the specified directory.

Types

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data []byte) error
}

Jump to

Keyboard shortcuts

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