MCPcopy
hub / github.com/larksuite/cli / TryLock

Method TryLock

internal/lockfile/lockfile.go:48–62  ·  view source on GitHub ↗

TryLock acquires an exclusive non-blocking lock; auto-released on process exit.

()

Source from the content-addressed store, hash-verified

46
47// TryLock acquires an exclusive non-blocking lock; auto-released on process exit.
48func (l *LockFile) TryLock() error {
49 if l.file != nil {
50 return fmt.Errorf("%w: %s", ErrHeld, l.path)
51 }
52 f, err := vfs.OpenFile(l.path, os.O_CREATE|os.O_RDWR, 0600)
53 if err != nil {
54 return fmt.Errorf("open lock file: %w", err)
55 }
56 if err := tryLockFile(f); err != nil {
57 f.Close()
58 return err
59 }
60 l.file = f
61 return nil
62}
63
64// Unlock keeps the file on disk to avoid inode-reuse races between unlock and competing open+flock.
65func (l *LockFile) Unlock() error {

Callers 15

TestTryLock_SuccessFunction · 0.80
TestTryLock_ConflictFunction · 0.80
TestTryLock_AlreadyHeldFunction · 0.80
TestTryLock_InvalidPathFunction · 0.80
TestUnlock_ReleasesLockFunction · 0.80
TestUnlock_IdempotentFunction · 0.80
WritePIDFileFunction · 0.80
isBusAliveFunction · 0.80
forkBusFunction · 0.80

Calls 3

OpenFileFunction · 0.92
tryLockFileFunction · 0.70
CloseMethod · 0.45