Make NoLock a global option
This commit is contained in:
parent
6edb7e02d0
commit
a1440c819b
5 changed files with 8 additions and 30 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
type CmdCheck struct {
|
||||
ReadData bool `long:"read-data" default:"false" description:"Read data blobs"`
|
||||
CheckUnused bool `long:"check-unused" default:"false" description:"Check for unused blobs"`
|
||||
NoLock bool `long:"no-lock" default:"false" description:"Do not lock repository, this allows checking read-only"`
|
||||
|
||||
global *GlobalOptions
|
||||
}
|
||||
|
@ -40,7 +39,7 @@ func (cmd CmdCheck) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !cmd.NoLock {
|
||||
if !cmd.global.NoLock {
|
||||
cmd.global.Verbosef("Create exclusive lock for repository\n")
|
||||
lock, err := lockRepoExclusive(repo)
|
||||
defer unlockRepo(lock)
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
)
|
||||
|
||||
type CmdList struct {
|
||||
NoLock bool `long:"no-lock" default:"false" description:"Do not lock repository, this allows listing a read-only repo"`
|
||||
|
||||
global *GlobalOptions
|
||||
}
|
||||
|
||||
|
@ -37,7 +35,7 @@ func (cmd CmdList) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !cmd.NoLock {
|
||||
if !cmd.global.NoLock {
|
||||
lock, err := lockRepo(repo)
|
||||
defer unlockRepo(lock)
|
||||
if err != nil {
|
||||
|
|
|
@ -13,7 +13,6 @@ type CmdRestore struct {
|
|||
Exclude []string `short:"e" long:"exclude" description:"Exclude a pattern (can be specified multiple times)"`
|
||||
Include []string `short:"i" long:"include" description:"Include a pattern, exclude everything else (can be specified multiple times)"`
|
||||
Target string `short:"t" long:"target" description:"Directory to restore to"`
|
||||
NoLock bool ` long:"no-lock" default:"false" description:"Do not lock repository, this allows restoring a read-only repo"`
|
||||
|
||||
global *GlobalOptions
|
||||
}
|
||||
|
@ -54,7 +53,7 @@ func (cmd CmdRestore) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !cmd.NoLock {
|
||||
if !cmd.global.NoLock {
|
||||
lock, err := lockRepo(repo)
|
||||
defer unlockRepo(lock)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,6 +24,7 @@ type GlobalOptions struct {
|
|||
Repo string `short:"r" long:"repo" description:"Repository directory to backup to/restore from"`
|
||||
CacheDir string ` long:"cache-dir" description:"Directory to use as a local cache"`
|
||||
Quiet bool `short:"q" long:"quiet" default:"false" description:"Do not output comprehensive progress report"`
|
||||
NoLock bool ` long:"no-lock" default:"false" description:"Do not lock the repo, this allows some operations on read-only repos."`
|
||||
|
||||
password string
|
||||
stdout io.Writer
|
||||
|
|
|
@ -73,20 +73,10 @@ func executeAndParseIDs(t testing.TB, cmd *CmdList, args ...string) backend.IDs
|
|||
return parseIDsFromReader(t, buf)
|
||||
}
|
||||
|
||||
func cmdListNoLock(t testing.TB, global GlobalOptions, tpe string) backend.IDs {
|
||||
cmd := &CmdList{global: &global, NoLock: true}
|
||||
return executeAndParseIDs(t, cmd, tpe)
|
||||
}
|
||||
|
||||
func cmdRestore(t testing.TB, global GlobalOptions, dir string, snapshotID backend.ID) {
|
||||
cmdRestoreExcludes(t, global, dir, snapshotID, nil)
|
||||
}
|
||||
|
||||
func cmdRestoreNoLock(t testing.TB, global GlobalOptions, dir string, snapshotID backend.ID) {
|
||||
cmd := &CmdRestore{global: &global, Target: dir, NoLock: true}
|
||||
OK(t, cmd.Execute([]string{snapshotID.String()}))
|
||||
}
|
||||
|
||||
func cmdRestoreExcludes(t testing.TB, global GlobalOptions, dir string, snapshotID backend.ID, excludes []string) {
|
||||
cmd := &CmdRestore{global: &global, Target: dir, Exclude: excludes}
|
||||
OK(t, cmd.Execute([]string{snapshotID.String()}))
|
||||
|
@ -114,16 +104,6 @@ func cmdCheckOutput(t testing.TB, global GlobalOptions) string {
|
|||
return string(buf.Bytes())
|
||||
}
|
||||
|
||||
func cmdCheckNoLock(t testing.TB, global GlobalOptions) {
|
||||
cmd := &CmdCheck{
|
||||
global: &global,
|
||||
ReadData: true,
|
||||
CheckUnused: true,
|
||||
NoLock: true,
|
||||
}
|
||||
OK(t, cmd.Execute(nil))
|
||||
}
|
||||
|
||||
func cmdRebuildIndex(t testing.TB, global GlobalOptions) {
|
||||
global.stdout = ioutil.Discard
|
||||
cmd := &CmdRebuildIndex{global: &global}
|
||||
|
@ -823,13 +803,14 @@ func TestCheckRestoreNoLock(t *testing.T) {
|
|||
})
|
||||
OK(t, err)
|
||||
|
||||
cmdCheckNoLock(t, global)
|
||||
global.NoLock = true
|
||||
cmdCheck(t, global)
|
||||
|
||||
snapshotIDs := cmdListNoLock(t, global, "snapshots")
|
||||
snapshotIDs := cmdList(t, global, "snapshots")
|
||||
if len(snapshotIDs) == 0 {
|
||||
t.Fatalf("found no snapshots")
|
||||
}
|
||||
|
||||
cmdRestoreNoLock(t, global, filepath.Join(env.base, "restore"), snapshotIDs[0])
|
||||
cmdRestore(t, global, filepath.Join(env.base, "restore"), snapshotIDs[0])
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue