MCPcopy Index your code
hub / github.com/dagger/container-use / GetLock

Method GetLock

repository/flock.go:52–75  ·  view source on GitHub ↗

GetLock returns a lock for the specified operation type

(lockType LockType)

Source from the content-addressed store, hash-verified

50
51// GetLock returns a lock for the specified operation type
52func (rlm *RepositoryLockManager) GetLock(lockType LockType) *RepositoryLock {
53 rlm.mu.Lock()
54 defer rlm.mu.Unlock()
55
56 if lock, exists := rlm.locks[lockType]; exists {
57 return lock
58 }
59
60 lockFileName := fmt.Sprintf("container-use-%x-%s.lock", hashString(rlm.repoPath), string(lockType))
61 lockDir := filepath.Join(os.TempDir(), "container-use-locks")
62 lockFile := filepath.Join(lockDir, lockFileName)
63
64 err := os.MkdirAll(lockDir, 0755)
65 if err != nil {
66 slog.Error("Failed to create lock directory", "error", err)
67 }
68
69 lock := &RepositoryLock{
70 flock: flock.New(lockFile),
71 }
72
73 rlm.locks[lockType] = lock
74 return lock
75}
76
77// WithLock executes a function while holding an exclusive lock for the specified lock type
78func (rlm *RepositoryLockManager) WithLock(ctx context.Context, lockType LockType, fn func() error) error {

Callers 2

WithLockMethod · 0.95
WithRLockMethod · 0.95

Calls 3

hashStringFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected