mirror of
https://github.com/restic/restic.git
synced 2026-11-21 07:05:09 +00:00
cmd/restic: Add command unlock, improve error message
This commit is contained in:
1 parent
0ad3d71f01
commit
e657287eac
4 files changed
+136
-20
No files matched your search
+22
-9
@@ -14,19 +14,32 @@ import (
|
||||
var globalLocks []*restic.Lock
|
||||
|
||||
func lockRepo(repo *repository.Repository) (*restic.Lock, error) {
|
||||
lock, err := restic.NewLock(repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
globalLocks = append(globalLocks, lock)
|
||||
|
||||
return lock, err
|
||||
return lockRepository(repo, false)
|
||||
}
|
||||
|
||||
func lockRepoExclusive(repo *repository.Repository) (*restic.Lock, error) {
|
||||
lock, err := restic.NewExclusiveLock(repo)
|
||||
return lockRepository(repo, true)
|
||||
}
|
||||
|
||||
func lockRepository(repo *repository.Repository, exclusive bool) (*restic.Lock, error) {
|
||||
lockFn := restic.NewLock
|
||||
if exclusive {
|
||||
lockFn = restic.NewExclusiveLock
|
||||
}
|
||||
|
||||
lock, err := lockFn(repo)
|
||||
if err != nil {
|
||||
if restic.IsAlreadyLocked(err) {
|
||||
tpe := ""
|
||||
if exclusive {
|
||||
tpe = " exclusive"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "unable to acquire%s lock for operation:\n", tpe)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user