mirror of
https://github.com/rclone/rclone.git
synced 2024-11-30 04:15:26 +01:00
check: Add stats showing total files matched.
This commit is contained in:
parent
d08453d402
commit
7782eda88e
@ -320,6 +320,13 @@ func (s *StatsInfo) GetLastError() error {
|
|||||||
return s.lastError
|
return s.lastError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetChecks returns the number of checks
|
||||||
|
func (s *StatsInfo) GetChecks() int64 {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
return s.checks
|
||||||
|
}
|
||||||
|
|
||||||
// FatalError sets the fatalError flag
|
// FatalError sets the fatalError flag
|
||||||
func (s *StatsInfo) FatalError() {
|
func (s *StatsInfo) FatalError() {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
|
@ -577,6 +577,7 @@ type checkMarch struct {
|
|||||||
noHashes int32
|
noHashes int32
|
||||||
srcFilesMissing int32
|
srcFilesMissing int32
|
||||||
dstFilesMissing int32
|
dstFilesMissing int32
|
||||||
|
matches int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// DstOnly have an object which is in the destination only
|
// DstOnly have an object which is in the destination only
|
||||||
@ -644,6 +645,7 @@ func (c *checkMarch) Match(dst, src fs.DirEntry) (recurse bool) {
|
|||||||
if differ {
|
if differ {
|
||||||
atomic.AddInt32(&c.differences, 1)
|
atomic.AddInt32(&c.differences, 1)
|
||||||
} else {
|
} else {
|
||||||
|
atomic.AddInt32(&c.matches, 1)
|
||||||
fs.Debugf(dstX, "OK")
|
fs.Debugf(dstX, "OK")
|
||||||
}
|
}
|
||||||
if noHash {
|
if noHash {
|
||||||
@ -711,6 +713,9 @@ func CheckFn(fdst, fsrc fs.Fs, check checkFn, oneway bool) error {
|
|||||||
if c.noHashes > 0 {
|
if c.noHashes > 0 {
|
||||||
fs.Logf(fdst, "%d hashes could not be checked", c.noHashes)
|
fs.Logf(fdst, "%d hashes could not be checked", c.noHashes)
|
||||||
}
|
}
|
||||||
|
if c.matches > 0 {
|
||||||
|
fs.Logf(fdst, "%d matching files", c.matches)
|
||||||
|
}
|
||||||
if c.differences > 0 {
|
if c.differences > 0 {
|
||||||
return errors.Errorf("%d differences found", c.differences)
|
return errors.Errorf("%d differences found", c.differences)
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -271,11 +273,17 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
|||||||
r := fstest.NewRun(t)
|
r := fstest.NewRun(t)
|
||||||
defer r.Finalise()
|
defer r.Finalise()
|
||||||
|
|
||||||
check := func(i int, wantErrors int64, oneway bool) {
|
check := func(i int, wantErrors int64, wantChecks int64, oneway bool) {
|
||||||
fs.Debugf(r.Fremote, "%d: Starting check test", i)
|
fs.Debugf(r.Fremote, "%d: Starting check test", i)
|
||||||
oldErrors := accounting.Stats.GetErrors()
|
accounting.Stats.ResetCounters()
|
||||||
|
var buf bytes.Buffer
|
||||||
|
log.SetOutput(&buf)
|
||||||
|
defer func() {
|
||||||
|
log.SetOutput(os.Stderr)
|
||||||
|
}()
|
||||||
err := checkFunction(r.Fremote, r.Flocal, oneway)
|
err := checkFunction(r.Fremote, r.Flocal, oneway)
|
||||||
gotErrors := accounting.Stats.GetErrors() - oldErrors
|
gotErrors := accounting.Stats.GetErrors()
|
||||||
|
gotChecks := accounting.Stats.GetChecks()
|
||||||
if wantErrors == 0 && err != nil {
|
if wantErrors == 0 && err != nil {
|
||||||
t.Errorf("%d: Got error when not expecting one: %v", i, err)
|
t.Errorf("%d: Got error when not expecting one: %v", i, err)
|
||||||
}
|
}
|
||||||
@ -285,21 +293,27 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
|||||||
if wantErrors != gotErrors {
|
if wantErrors != gotErrors {
|
||||||
t.Errorf("%d: Expecting %d errors but got %d", i, wantErrors, gotErrors)
|
t.Errorf("%d: Expecting %d errors but got %d", i, wantErrors, gotErrors)
|
||||||
}
|
}
|
||||||
|
if gotChecks > 0 && !strings.Contains(buf.String(), "matching files") {
|
||||||
|
t.Errorf("%d: Total files matching line missing", i)
|
||||||
|
}
|
||||||
|
if wantChecks != gotChecks {
|
||||||
|
t.Errorf("%d: Expecting %d total matching files but got %d", i, wantChecks, gotChecks)
|
||||||
|
}
|
||||||
fs.Debugf(r.Fremote, "%d: Ending check test", i)
|
fs.Debugf(r.Fremote, "%d: Ending check test", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
file1 := r.WriteBoth("rutabaga", "is tasty", t3)
|
file1 := r.WriteBoth("rutabaga", "is tasty", t3)
|
||||||
fstest.CheckItems(t, r.Fremote, file1)
|
fstest.CheckItems(t, r.Fremote, file1)
|
||||||
fstest.CheckItems(t, r.Flocal, file1)
|
fstest.CheckItems(t, r.Flocal, file1)
|
||||||
check(1, 0, false)
|
check(1, 0, 1, false)
|
||||||
|
|
||||||
file2 := r.WriteFile("potato2", "------------------------------------------------------------", t1)
|
file2 := r.WriteFile("potato2", "------------------------------------------------------------", t1)
|
||||||
fstest.CheckItems(t, r.Flocal, file1, file2)
|
fstest.CheckItems(t, r.Flocal, file1, file2)
|
||||||
check(2, 1, false)
|
check(2, 1, 1, false)
|
||||||
|
|
||||||
file3 := r.WriteObject("empty space", "", t2)
|
file3 := r.WriteObject("empty space", "", t2)
|
||||||
fstest.CheckItems(t, r.Fremote, file1, file3)
|
fstest.CheckItems(t, r.Fremote, file1, file3)
|
||||||
check(3, 2, false)
|
check(3, 2, 1, false)
|
||||||
|
|
||||||
file2r := file2
|
file2r := file2
|
||||||
if fs.Config.SizeOnly {
|
if fs.Config.SizeOnly {
|
||||||
@ -308,16 +322,16 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
|||||||
r.WriteObject("potato2", "------------------------------------------------------------", t1)
|
r.WriteObject("potato2", "------------------------------------------------------------", t1)
|
||||||
}
|
}
|
||||||
fstest.CheckItems(t, r.Fremote, file1, file2r, file3)
|
fstest.CheckItems(t, r.Fremote, file1, file2r, file3)
|
||||||
check(4, 1, false)
|
check(4, 1, 2, false)
|
||||||
|
|
||||||
r.WriteFile("empty space", "", t2)
|
r.WriteFile("empty space", "", t2)
|
||||||
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
||||||
check(5, 0, false)
|
check(5, 0, 3, false)
|
||||||
|
|
||||||
file4 := r.WriteObject("remotepotato", "------------------------------------------------------------", t1)
|
file4 := r.WriteObject("remotepotato", "------------------------------------------------------------", t1)
|
||||||
fstest.CheckItems(t, r.Fremote, file1, file2r, file3, file4)
|
fstest.CheckItems(t, r.Fremote, file1, file2r, file3, file4)
|
||||||
check(6, 1, false)
|
check(6, 1, 3, false)
|
||||||
check(7, 0, true)
|
check(7, 0, 3, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheck(t *testing.T) {
|
func TestCheck(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user