2015-06-27 13:50:36 +00:00
|
|
|
package main
|
|
|
|
|
2016-02-14 14:29:28 +00:00
|
|
|
import "restic"
|
2015-06-27 13:50:36 +00:00
|
|
|
|
|
|
|
type CmdUnlock struct {
|
|
|
|
RemoveAll bool `long:"remove-all" description:"Remove all locks, even stale ones"`
|
|
|
|
|
|
|
|
global *GlobalOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
_, err := parser.AddCommand("unlock",
|
|
|
|
"remove locks",
|
|
|
|
"The unlock command checks for stale locks and removes them",
|
|
|
|
&CmdUnlock{global: &globalOpts})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd CmdUnlock) Usage() string {
|
|
|
|
return "[unlock-options]"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd CmdUnlock) Execute(args []string) error {
|
|
|
|
repo, err := cmd.global.OpenRepository()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fn := restic.RemoveStaleLocks
|
|
|
|
if cmd.RemoveAll {
|
|
|
|
fn = restic.RemoveAllLocks
|
|
|
|
}
|
|
|
|
|
|
|
|
err = fn(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.global.Verbosef("successfully removed locks\n")
|
|
|
|
return nil
|
|
|
|
}
|