staging_lockfile

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StagingLockFile

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

StagingLockFile represents a file lock used to coordinate access to staging areas. Typical usage is via CreateAndLock or TryLockPath, both of which return a StagingLockFile that must eventually be released with UnlockAndDelete. This ensures that access to the staging file is properly synchronized both within and across processes.

WARNING: This struct MUST NOT be created manually. Use the provided helper functions instead.

func CreateAndLock

func CreateAndLock(dir string, pattern string) (*StagingLockFile, string, error)

CreateAndLock creates a new temporary file in the specified directory with the given pattern, then creates and locks a StagingLockFile for it. The file is created using os.CreateTemp. Typically, the caller would use the returned lock file path to derive a path to the lock-controlled resource (e.g. by replacing the "pattern" part of the returned file name with a different prefix) Caller MUST call UnlockAndDelete() on the returned StagingLockFile to release the lock and delete the file.

Returns:

  • The locked StagingLockFile
  • The name of created lock file
  • Any error that occurred during the process

If the file cannot be locked, this function will retry up to maxRetries times before failing.

func TryLockPath

func TryLockPath(path string) (*StagingLockFile, error)

TryLockPath attempts to acquire a lock on an specific path. If the file does not exist, it will be created.

Warning: If acquiring a lock is successful, it returns a new StagingLockFile instance for the file. Caller MUST call UnlockAndDelete() on the returned StagingLockFile to release the lock and delete the file.

func (*StagingLockFile) UnlockAndDelete

func (l *StagingLockFile) UnlockAndDelete() error

UnlockAndDelete releases the lock, removes the associated file from the filesystem.

WARNING: After this operation, the StagingLockFile becomes invalid for further use.

Jump to

Keyboard shortcuts

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