mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
Allow checking a read-only repo with --no-lock
This commit is contained in:
parent
acba82c8f7
commit
c79dcbd7c4
@ -9,8 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CmdCheck struct {
|
type CmdCheck struct {
|
||||||
ReadData bool `long:"read-data" description:"Read data blobs" default:"false"`
|
ReadData bool `long:"read-data" default:"false" description:"Read data blobs"`
|
||||||
CheckUnused bool `long:"check-unused" description:"Check for unused blobs" default:"false"`
|
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
|
global *GlobalOptions
|
||||||
}
|
}
|
||||||
@ -39,11 +40,13 @@ func (cmd CmdCheck) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.global.Verbosef("Create exclusive lock for repository\n")
|
if !cmd.NoLock {
|
||||||
lock, err := lockRepoExclusive(repo)
|
cmd.global.Verbosef("Create exclusive lock for repository\n")
|
||||||
defer unlockRepo(lock)
|
lock, err := lockRepoExclusive(repo)
|
||||||
if err != nil {
|
defer unlockRepo(lock)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chkr := checker.New(repo)
|
chkr := checker.New(repo)
|
||||||
|
@ -103,6 +103,16 @@ func cmdCheckOutput(t testing.TB, global GlobalOptions) string {
|
|||||||
return string(buf.Bytes())
|
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) {
|
func cmdRebuildIndex(t testing.TB, global GlobalOptions) {
|
||||||
global.stdout = ioutil.Discard
|
global.stdout = ioutil.Discard
|
||||||
cmd := &CmdRebuildIndex{global: &global}
|
cmd := &CmdRebuildIndex{global: &global}
|
||||||
@ -788,3 +798,20 @@ func TestOptimizeRemoveUnusedBlobs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckRestoreNoLock(t *testing.T) {
|
||||||
|
withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) {
|
||||||
|
datafile := filepath.Join("testdata", "repo-restore-permissions-test.tar.gz")
|
||||||
|
SetupTarTestFixture(t, env.base, datafile)
|
||||||
|
|
||||||
|
err := filepath.Walk(env.repo, func(p string, fi os.FileInfo, e error) error {
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return os.Chmod(p, fi.Mode() & ^(os.FileMode(0222)))
|
||||||
|
})
|
||||||
|
OK(t, err)
|
||||||
|
|
||||||
|
cmdCheckNoLock(t, global)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user