func unlockRepo(lock *restic.Lock) error { globalLocks.Lock() defer globalLocks.Unlock() debug.Log("unlocking repository") if err := lock.Unlock(); err != nil { debug.Log("error while unlocking: %v", err) return err } for i := 0; i < len(globalLocks.locks); i++ { if lock == globalLocks.locks[i] { globalLocks.locks = append(globalLocks.locks[:i], globalLocks.locks[i+1:]...) return nil } } return nil }
func TestLockStale(t *testing.T) { hostname, err := os.Hostname() OK(t, err) otherHostname := "other-" + hostname for i, test := range staleLockTests { lock := restic.Lock{ Time: test.timestamp, PID: test.pid, Hostname: hostname, } Assert(t, lock.Stale() == test.stale, "TestStaleLock: test %d failed: expected stale: %v, got %v", i, test.stale, !test.stale) lock.Hostname = otherHostname Assert(t, lock.Stale() == test.staleOnOtherHost, "TestStaleLock: test %d failed: expected staleOnOtherHost: %v, got %v", i, test.staleOnOtherHost, !test.staleOnOtherHost) } }