2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

cmd/restic: Add locks to commands

This commit is contained in:
Alexander Neumann 2015-06-27 14:40:18 +02:00
parent 7d2699b429
commit 65a0def949
10 changed files with 62 additions and 0 deletions

View File

@ -220,6 +220,12 @@ func (cmd CmdBackup) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
err = repo.LoadIndex()
if err != nil {
return err

View File

@ -34,6 +34,12 @@ func (cmd CmdCache) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
cache, err := restic.NewCache(repo, cmd.global.CacheDir)
if err != nil {
return err

View File

@ -42,6 +42,12 @@ func (cmd CmdCat) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
tpe := args[0]
var id backend.ID

View File

@ -109,6 +109,12 @@ func (cmd CmdDump) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
err = repo.LoadIndex()
if err != nil {
return err

View File

@ -162,6 +162,12 @@ func (c CmdFind) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
c.pattern = args[0]
if c.Snapshot != "" {

View File

@ -195,6 +195,12 @@ func (cmd CmdFsck) Execute(args []string) error {
return err
}
lock, err := restic.NewExclusiveLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
err = repo.LoadIndex()
if err != nil {
return err

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/repository"
)
@ -121,6 +122,12 @@ func (cmd CmdKey) Execute(args []string) error {
return err
}
lock, err := restic.NewExclusiveLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
switch args[0] {
case "list":
return cmd.listKeys(repo)

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/restic/restic"
"github.com/restic/restic/backend"
)
@ -35,6 +36,12 @@ func (cmd CmdList) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
var t backend.Type
switch args[0] {
case "blobs":

View File

@ -35,6 +35,12 @@ func (cmd CmdRestore) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
err = repo.LoadIndex()
if err != nil {
return err

View File

@ -99,6 +99,12 @@ func (cmd CmdSnapshots) Execute(args []string) error {
return err
}
lock, err := restic.NewLock(repo)
defer lock.Unlock()
if err != nil {
return err
}
tab := NewTable()
tab.Header = fmt.Sprintf("%-8s %-19s %-10s %s", "ID", "Date", "Source", "Directory")
tab.RowFormat = "%-8s %-19s %-10s %s"