github.com/mckael/restic@v0.8.3/cmd/restic/cmd_unlock.go (about) 1 package main 2 3 import ( 4 "github.com/restic/restic/internal/restic" 5 "github.com/spf13/cobra" 6 ) 7 8 var unlockCmd = &cobra.Command{ 9 Use: "unlock", 10 Short: "Remove locks other processes created", 11 Long: ` 12 The "unlock" command removes stale locks that have been created by other restic processes. 13 `, 14 DisableAutoGenTag: true, 15 RunE: func(cmd *cobra.Command, args []string) error { 16 return runUnlock(unlockOptions, globalOptions) 17 }, 18 } 19 20 // UnlockOptions collects all options for the unlock command. 21 type UnlockOptions struct { 22 RemoveAll bool 23 } 24 25 var unlockOptions UnlockOptions 26 27 func init() { 28 cmdRoot.AddCommand(unlockCmd) 29 30 unlockCmd.Flags().BoolVar(&unlockOptions.RemoveAll, "remove-all", false, "remove all locks, even non-stale ones") 31 } 32 33 func runUnlock(opts UnlockOptions, gopts GlobalOptions) error { 34 repo, err := OpenRepository(gopts) 35 if err != nil { 36 return err 37 } 38 39 fn := restic.RemoveStaleLocks 40 if opts.RemoveAll { 41 fn = restic.RemoveAllLocks 42 } 43 44 err = fn(gopts.ctx, repo) 45 if err != nil { 46 return err 47 } 48 49 Verbosef("successfully removed locks\n") 50 return nil 51 }