restic/cmd/restic/cmd_unlock.go

57 lines
1.2 KiB
Go
Raw Normal View History

package main
2016-09-17 10:36:05 +00:00
import (
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
2016-09-17 10:36:05 +00:00
"github.com/spf13/cobra"
)
var unlockCmd = &cobra.Command{
Use: "unlock",
Short: "Remove locks other processes created",
2016-09-17 10:36:05 +00:00
Long: `
The "unlock" command removes stale locks that have been created by other restic processes.
EXIT STATUS
===========
Exit status is 0 if the command was successful, and non-zero if there was any error.
2016-09-17 10:36:05 +00:00
`,
DisableAutoGenTag: true,
2016-09-17 10:36:05 +00:00
RunE: func(cmd *cobra.Command, args []string) error {
return runUnlock(unlockOptions, globalOptions)
},
}
2016-09-17 10:36:05 +00:00
// UnlockOptions collects all options for the unlock command.
type UnlockOptions struct {
RemoveAll bool
}
2016-09-17 10:36:05 +00:00
var unlockOptions UnlockOptions
func init() {
2016-09-17 10:36:05 +00:00
cmdRoot.AddCommand(unlockCmd)
unlockCmd.Flags().BoolVar(&unlockOptions.RemoveAll, "remove-all", false, "remove all locks, even non-stale ones")
}
2016-09-17 10:36:05 +00:00
func runUnlock(opts UnlockOptions, gopts GlobalOptions) error {
repo, err := OpenRepository(gopts)
if err != nil {
return err
}
fn := restic.RemoveStaleLocks
2016-09-17 10:36:05 +00:00
if opts.RemoveAll {
fn = restic.RemoveAllLocks
}
err = fn(gopts.ctx, repo)
if err != nil {
return err
}
2016-09-17 10:36:05 +00:00
Verbosef("successfully removed locks\n")
return nil
}