package staging_lockfile
import "github.com/containers/storage/internal/staging_lockfile"
Index ¶
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.
Source Files ¶
- Version
- v1.59.0 (latest)
- Published
- Jul 14, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 2 days ago –
Tools for package owners.