MCPcopy
hub / github.com/rclone/rclone / setLockFile

Method setLockFile

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

Source from the content-addressed store, hash-verified

27}
28
29func (b *bisyncRun) setLockFile() (err error) {
30 b.lockFile = ""
31 b.setLockFileExpiration()
32 if !b.opt.DryRun {
33 b.lockFile = b.basePath + ".lck"
34 if bilib.FileExists(b.lockFile) {
35 if !b.lockFileIsExpired() {
36 errTip := Color(terminal.MagentaFg, "Tip: this indicates that another bisync run (of these same paths) either is still running or was interrupted before completion. \n")
37 errTip += Color(terminal.MagentaFg, "If you're SURE you want to override this safety feature, you can delete the lock file with the following command, then run bisync again: \n")
38 errTip += fmt.Sprintf(Color(terminal.HiRedFg, "rclone deletefile \"%s\""), b.lockFile)
39 return fmt.Errorf(Color(terminal.RedFg, "prior lock file found: %s \n")+errTip, Color(terminal.HiYellowFg, b.lockFile))
40 }
41 }
42
43 pidStr := []byte(strconv.Itoa(os.Getpid()))
44 if err = os.WriteFile(b.lockFile, pidStr, bilib.PermSecure); err != nil {
45 return fmt.Errorf(Color(terminal.RedFg, "cannot create lock file: %s: %w"), b.lockFile, err)
46 }
47 fs.Debugf(nil, "Lock file created: %s", b.lockFile)
48 b.renewLockFile()
49 b.lockFileOpt.stopRenewal = b.startLockRenewal()
50 }
51 return nil
52}
53
54func (b *bisyncRun) removeLockFile() (err error) {
55 if b.lockFile != "" {

Callers 1

BisyncFunction · 0.95

Calls 9

setLockFileExpirationMethod · 0.95
lockFileIsExpiredMethod · 0.95
renewLockFileMethod · 0.95
startLockRenewalMethod · 0.95
FileExistsFunction · 0.92
DebugfFunction · 0.92
ColorFunction · 0.85
ErrorfMethod · 0.45
WriteFileMethod · 0.45

Tested by

no test coverage detected