()
| 27 | } |
| 28 | |
| 29 | func (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 | |
| 54 | func (b *bisyncRun) removeLockFile() (err error) { |
| 55 | if b.lockFile != "" { |
no test coverage detected