MCPcopy Create free account
hub / github.com/cogentcore/core / lockFile

Method lockFile

core/windowgeometry.go:78–109  ·  view source on GitHub ↗

lockFile attempts to create the window geometry lock file

()

Source from the content-addressed store, hash-verified

76
77// lockFile attempts to create the window geometry lock file
78func (ws *windowGeometrySaver) lockFile() error {
79 pdir := TheApp.CogentCoreDataDir()
80 pnm := filepath.Join(pdir, ws.filename+".lck")
81 for rep := 0; rep < 10; rep++ {
82 if _, err := os.Stat(pnm); os.IsNotExist(err) {
83 b, _ := time.Now().MarshalJSON()
84 err = os.WriteFile(pnm, b, 0644)
85 if err == nil {
86 return nil
87 }
88 }
89 b, err := os.ReadFile(pnm)
90 if err != nil {
91 time.Sleep(ws.lockSleep)
92 continue
93 }
94 var lts time.Time
95 err = lts.UnmarshalJSON(b)
96 if err != nil {
97 time.Sleep(ws.lockSleep)
98 continue
99 }
100 if time.Since(lts) > 1*time.Second {
101 // log.Printf("WindowGeometry: lock file stale: %v\n", lts.String())
102 os.Remove(pnm)
103 continue
104 }
105 // log.Printf("WindowGeometry: waiting for lock file: %v\n", lts.String())
106 time.Sleep(ws.lockSleep)
107 }
108 return errors.New("WinGeom could not lock lock file")
109}
110
111// UnLockFile unlocks the window geometry lock file (just removes it)
112func (ws *windowGeometrySaver) unlockFile() {

Callers 1

saveCachedMethod · 0.95

Calls 8

NewFunction · 0.92
ReadFileMethod · 0.80
SinceMethod · 0.80
CogentCoreDataDirMethod · 0.65
StatMethod · 0.45
MarshalJSONMethod · 0.45
NowMethod · 0.45
UnmarshalJSONMethod · 0.45

Tested by

no test coverage detected