fileutil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CreateFlagFile

func CreateFlagFile(dir string, filename string, msg proto.Message) (err error)

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

func Exist

func Exist(name string) (bool, error)

Exist returns whether the specified filesystem entry exists.

func ExtractTarBz2

func ExtractTarBz2(bz2fn string, toDir string) error

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

func GetAppNameFromFilename

func GetAppNameFromFilename(soName string) string

GetAppNameFromFilename returns the app name from the filename.

func GetFlagFileContent

func GetFlagFileContent(dir string, filename string, msg proto.Message) 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 GetPossibleCPPSOFiles

func GetPossibleCPPSOFiles(path string) []string

GetPossibleCPPSOFiles returns a list of possible .so files found in the specified path.

func GetPossibleSOFiles

func GetPossibleSOFiles(path string) []string

GetPossibleSOFiles returns a list of possible .so files.

func HasFlagFile

func HasFlagFile(dir string, filename string) bool

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

func IsDirMarkedAsDeleted

func IsDirMarkedAsDeleted(dir string) (bool, error)

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

func MarkDirAsDeleted

func MarkDirAsDeleted(dir string, msg proto.Message) error

MarkDirAsDeleted marks the specified directory as deleted.

func Mkdir

func Mkdir(dir string) error

Mkdir creates the specified dir.

func MkdirAll

func MkdirAll(dir string) error

MkdirAll creates the specified dir along with any necessary parents.

func RemoveFlagFile

func RemoveFlagFile(dir string, filename string) error

RemoveFlagFile removes the specified flag file.

func SyncDir

func SyncDir(dir string) (err error)

SyncDir calls fsync on the specified directory.

Types

type ChunkFile

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

ChunkFile is the snapshot chunk file being transferred.

func CreateChunkFile

func CreateChunkFile(fp string) (*ChunkFile, error)

CreateChunkFile creates a new chunk file.

func OpenChunkFileForAppend

func OpenChunkFileForAppend(fp string) (*ChunkFile, error)

OpenChunkFileForAppend opens the chunk file at fp for appending.

func OpenChunkFileForRead

func OpenChunkFileForRead(fp string) (*ChunkFile, error)

OpenChunkFileForRead opens for the chunk file for read-only operation.

func (*ChunkFile) Close

func (cf *ChunkFile) Close()

Close closes the chunk file.

func (*ChunkFile) Read

func (cf *ChunkFile) Read(data []byte) (int, error)

Read reads from the file.

func (*ChunkFile) SeekFromBeginning

func (cf *ChunkFile) SeekFromBeginning(offset int64) (int64, error)

SeekFromBeginning seeks the underlying file from the beginning.

func (*ChunkFile) Sync

func (cf *ChunkFile) Sync() error

Sync syncs the chunk file.

func (*ChunkFile) Write

func (cf *ChunkFile) Write(data []byte) (int, error)

Write writes the specified data to the chunk file.

type Flock

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

Flock is the struct type to handle file locking. All fields are unexported, with access to some of the fields provided by getter methods (Path() and Locked()).

func New

func New(path string) *Flock

New returns a new instance of *Flock. The only parameter it takes is the path to the desired lockfile.

func NewFlock deprecated

func NewFlock(path string) *Flock

NewFlock returns a new instance of *Flock. The only parameter it takes is the path to the desired lockfile.

Deprecated: Use New instead.

func (*Flock) Close

func (f *Flock) Close() error

Close is equivalent to calling Unlock.

This will release the lock and close the underlying file descriptor. It will not remove the file from disk, that's up to your application.

func (*Flock) Lock

func (f *Flock) Lock() error

Lock is a blocking call to try and take an exclusive file lock. It will wait until it is able to obtain the exclusive file lock. It's recommended that TryLock() be used over this function. This function may block the ability to query the current Locked() or RLocked() status due to a RW-mutex lock.

If we are already exclusive-locked, this function short-circuits and returns immediately assuming it can take the mutex lock.

If the *Flock has a shared lock (RLock), this may transparently replace the shared lock with an exclusive lock on some UNIX-like operating systems. Be careful when using exclusive locks in conjunction with shared locks (RLock()), because calling Unlock() may accidentally release the exclusive lock that was once a shared lock.

func (*Flock) Locked

func (f *Flock) Locked() bool

Locked returns the lock state (locked: true, unlocked: false).

Warning: by the time you use the returned value, the state may have changed.

func (*Flock) Path

func (f *Flock) Path() string

Path returns the path as provided in NewFlock().

func (*Flock) RLock

func (f *Flock) RLock() error

RLock is a blocking call to try and take a shared file lock. It will wait until it is able to obtain the shared file lock. It's recommended that TryRLock() be used over this function. This function may block the ability to query the current Locked() or RLocked() status due to a RW-mutex lock.

If we are already shared-locked, this function short-circuits and returns immediately assuming it can take the mutex lock.

func (*Flock) RLocked

func (f *Flock) RLocked() bool

RLocked returns the read lock state (locked: true, unlocked: false).

Warning: by the time you use the returned value, the state may have changed.

func (*Flock) String

func (f *Flock) String() string

func (*Flock) TryLock

func (f *Flock) TryLock() (bool, error)

TryLock is the preferred function for taking an exclusive file lock. This function takes an RW-mutex lock before it tries to lock the file, so there is the possibility that this function may block for a short time if another goroutine is trying to take any action.

The actual file lock is non-blocking. If we are unable to get the exclusive file lock, the function will return false instead of waiting for the lock. If we get the lock, we also set the *Flock instance as being exclusive-locked.

func (*Flock) TryLockContext

func (f *Flock) TryLockContext(ctx context.Context, retryDelay time.Duration) (bool, error)

TryLockContext repeatedly tries to take an exclusive lock until one of the conditions is met: TryLock succeeds, TryLock fails with error, or Context Done channel is closed.

func (*Flock) TryRLock

func (f *Flock) TryRLock() (bool, error)

TryRLock is the preferred function for taking a shared file lock. This function takes an RW-mutex lock before it tries to lock the file, so there is the possibility that this function may block for a short time if another goroutine is trying to take any action.

The actual file lock is non-blocking. If we are unable to get the shared file lock, the function will return false instead of waiting for the lock. If we get the lock, we also set the *Flock instance as being share-locked.

func (*Flock) TryRLockContext

func (f *Flock) TryRLockContext(ctx context.Context, retryDelay time.Duration) (bool, error)

TryRLockContext repeatedly tries to take a shared lock until one of the conditions is met: TryRLock succeeds, TryRLock fails with error, or Context Done channel is closed.

func (*Flock) Unlock

func (f *Flock) Unlock() error

Unlock is a function to unlock the file. This file takes a RW-mutex lock, so while it is running the Locked() and RLocked() functions will be blocked.

This function short-circuits if we are unlocked already. If not, it calls syscall.LOCK_UN on the file and closes the file descriptor. It does not remove the file from disk. It's up to your application to do.

Please note, if your shared lock became an exclusive lock this may unintentionally drop the exclusive lock if called by the consumer that believes they have a shared lock. Please see Lock() for more details.

Jump to

Keyboard shortcuts

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