File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,19 +96,20 @@ func withSentinelLock(sentinelPath string, fn func() error) error {
9696 // Open or create the sentinel file just to acquire the lock fd.
9797 // We do NOT read/write through this fd to keep flock + atomic-write
9898 // concerns separate.
99- lockFile , err := os .OpenFile (sentinelPath , os .O_RDWR | os .O_CREATE , 0o644 )
99+ lockFile , err := os .OpenFile (sentinelPath , os .O_RDWR | os .O_CREATE , 0o600 )
100100 if err != nil {
101101 return fmt .Errorf ("failed to open sentinel for locking: %w" , err )
102102 }
103103 defer func () {
104104 _ = lockFile .Close ()
105105 }()
106106
107- if err := syscall .Flock (int (lockFile .Fd ()), syscall .LOCK_EX ); err != nil {
107+ fd := int (lockFile .Fd ()) //nolint:gosec // os.File.Fd returns uintptr but the underlying OS fd is always a valid int on unix
108+ if err := syscall .Flock (fd , syscall .LOCK_EX ); err != nil {
108109 return fmt .Errorf ("failed to acquire sentinel lock: %w" , err )
109110 }
110111 defer func () {
111- _ = syscall .Flock (int ( lockFile . Fd ()) , syscall .LOCK_UN )
112+ _ = syscall .Flock (fd , syscall .LOCK_UN )
112113 }()
113114
114115 return fn ()
You can’t perform that action at this time.
0 commit comments