MCPcopy
hub / github.com/kubernetes/client-go / lockFile

Function lockFile

tools/clientcmd/loader.go:423–440  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

421}
422
423func lockFile(filename string) error {
424 // TODO: find a way to do this with actual file locks. Will
425 // probably need separate solution for windows and Linux.
426
427 // Make sure the dir exists before we try to create a lock file.
428 dir := filepath.Dir(filename)
429 if _, err := os.Stat(dir); os.IsNotExist(err) {
430 if err = os.MkdirAll(dir, 0755); err != nil {
431 return err
432 }
433 }
434 f, err := os.OpenFile(lockName(filename), os.O_CREATE|os.O_EXCL, 0)
435 if err != nil {
436 return err
437 }
438 f.Close()
439 return nil
440}
441
442func unlockFile(filename string) error {
443 return os.Remove(lockName(filename))

Callers 2

TestFileLockingFunction · 0.85
ModifyConfigFunction · 0.85

Calls 2

lockNameFunction · 0.85
CloseMethod · 0.65

Tested by 1

TestFileLockingFunction · 0.68