MCPcopy Index your code
hub / github.com/rclone/rclone / lockFileIsExpired

Method lockFileIsExpired

cmd/bisync/lockfile.go:96–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94}
95
96func (b *bisyncRun) lockFileIsExpired() bool {
97 if b.lockFile != "" && bilib.FileExists(b.lockFile) {
98 rdf, err := os.Open(b.lockFile)
99 b.handleErr(b.lockFile, "error reading lock file", err, true, true)
100 dec := json.NewDecoder(rdf)
101 var decodeErr error
102 for {
103 if err := dec.Decode(&b.lockFileOpt.data); err != nil {
104 if err != io.EOF {
105 decodeErr = err
106 }
107 break
108 }
109 }
110 b.handleErr(b.lockFile, "error closing file", rdf.Close(), true, true)
111 if decodeErr != nil {
112 if b.opt.MaxLock < basicallyforever {
113 fs.Infof(b.lockFile, Color(terminal.YellowFg, "Lock file is unreadable (decode error: %v) and --max-lock is set. Treating as expired."), decodeErr)
114 markFailed(b.listing1)
115 markFailed(b.listing2)
116 return true
117 }
118 fs.Errorf(b.lockFile, Color(terminal.RedFg, "Lock file exists, but contents are unreadable. (decode error: %v)"), decodeErr)
119 return false
120 }
121 if !b.lockFileOpt.data.TimeExpires.IsZero() && b.lockFileOpt.data.TimeExpires.Before(time.Now()) {
122 fs.Infof(b.lockFile, Color(terminal.GreenFg, "Lock file found, but it expired at %v. Will delete it and proceed."), b.lockFileOpt.data.TimeExpires)
123 markFailed(b.listing1) // listing is untrusted so force revert to prior (if --recover) or create new ones (if --resync)
124 markFailed(b.listing2)
125 return true
126 }
127 fs.Infof(b.lockFile, Color(terminal.RedFg, "Valid lock file found. Expires at %v. (%v from now)"), b.lockFileOpt.data.TimeExpires, time.Since(b.lockFileOpt.data.TimeExpires).Abs().Round(time.Second))
128 prettyprint(b.lockFileOpt.data, "Lockfile info", fs.LogLevelInfo)
129 }
130 return false
131}
132
133// StartLockRenewal renews the lockfile every --max-lock minus one minute.
134//

Calls 11

handleErrMethod · 0.95
FileExistsFunction · 0.92
InfofFunction · 0.92
ErrorfFunction · 0.92
ColorFunction · 0.85
markFailedFunction · 0.85
prettyprintFunction · 0.85
IsZeroMethod · 0.80
OpenMethod · 0.65
DecodeMethod · 0.65
CloseMethod · 0.65