Stop repository if the directory disappears (fixes #154)
This commit is contained in:
parent
482795bab0
commit
f39e105101
File diff suppressed because one or more lines are too long
@ -285,3 +285,13 @@ func ensureNodePresent(nodes []NodeConfiguration, myID string) []NodeConfigurati
|
|||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func invalidateRepo(repoID string, err error) {
|
||||||
|
for i := range cfg.Repositories {
|
||||||
|
repo := &cfg.Repositories[i]
|
||||||
|
if repo.ID == repoID {
|
||||||
|
repo.Invalid = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -559,7 +559,7 @@ func (m *Model) ScanRepos() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) ScanRepo(repo string) {
|
func (m *Model) ScanRepo(repo string) error {
|
||||||
sup := &suppressor{threshold: int64(cfg.Options.MaxChangeKbps)}
|
sup := &suppressor{threshold: int64(cfg.Options.MaxChangeKbps)}
|
||||||
m.rmut.RLock()
|
m.rmut.RLock()
|
||||||
w := &scanner.Walker{
|
w := &scanner.Walker{
|
||||||
@ -572,9 +572,13 @@ func (m *Model) ScanRepo(repo string) {
|
|||||||
}
|
}
|
||||||
m.rmut.RUnlock()
|
m.rmut.RUnlock()
|
||||||
m.setState(repo, RepoScanning)
|
m.setState(repo, RepoScanning)
|
||||||
fs, _ := w.Walk()
|
fs, _, err := w.Walk()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
m.ReplaceLocal(repo, fs)
|
m.ReplaceLocal(repo, fs)
|
||||||
m.setState(repo, RepoIdle)
|
m.setState(repo, RepoIdle)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) SaveIndexes(dir string) {
|
func (m *Model) SaveIndexes(dir string) {
|
||||||
|
|||||||
@ -173,7 +173,11 @@ func (p *puller) run() {
|
|||||||
if debugPull {
|
if debugPull {
|
||||||
dlog.Printf("%q: time for rescan", p.repo)
|
dlog.Printf("%q: time for rescan", p.repo)
|
||||||
}
|
}
|
||||||
p.model.ScanRepo(p.repo)
|
err := p.model.ScanRepo(p.repo)
|
||||||
|
if err != nil {
|
||||||
|
invalidateRepo(p.repo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
@ -190,7 +194,11 @@ func (p *puller) runRO() {
|
|||||||
if debugPull {
|
if debugPull {
|
||||||
dlog.Printf("%q: time for rescan", p.repo)
|
dlog.Printf("%q: time for rescan", p.repo)
|
||||||
}
|
}
|
||||||
p.model.ScanRepo(p.repo)
|
err := p.model.ScanRepo(p.repo)
|
||||||
|
if err != nil {
|
||||||
|
invalidateRepo(p.repo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -142,7 +142,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($scope.model[repo].invalid !== '') {
|
if ($scope.model[repo].invalid !== '') {
|
||||||
return 'text-warning';
|
return 'text-danger';
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = '' + $scope.model[repo].state;
|
var state = '' + $scope.model[repo].state;
|
||||||
|
|||||||
@ -134,7 +134,7 @@
|
|||||||
<ul class="list-unstyled" ng-repeat="repo in repos">
|
<ul class="list-unstyled" ng-repeat="repo in repos">
|
||||||
<li>
|
<li>
|
||||||
<span class="text-monospace">{{repo.Directory}}</span>
|
<span class="text-monospace">{{repo.Directory}}</span>
|
||||||
<span ng-if="repo.Invalid" class="label label-danger">Invalid: {{repo.Invalid}}</span>
|
<span ng-if="model[repo.ID].invalid" class="label label-danger">{{model[repo.ID].invalid}}</span>
|
||||||
<ul class="list-no-bullet">
|
<ul class="list-no-bullet">
|
||||||
<li>
|
<li>
|
||||||
<div class="li-column" title="Repository ID">
|
<div class="li-column" title="Repository ID">
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package scanner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -51,12 +52,18 @@ type CurrentFiler interface {
|
|||||||
|
|
||||||
// Walk returns the list of files found in the local repository by scanning the
|
// Walk returns the list of files found in the local repository by scanning the
|
||||||
// file system. Files are blockwise hashed.
|
// file system. Files are blockwise hashed.
|
||||||
func (w *Walker) Walk() (files []File, ignore map[string][]string) {
|
func (w *Walker) Walk() (files []File, ignore map[string][]string, err error) {
|
||||||
w.lazyInit()
|
w.lazyInit()
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
dlog.Println("Walk", w.Dir, w.BlockSize, w.IgnoreFile)
|
dlog.Println("Walk", w.Dir, w.BlockSize, w.IgnoreFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = checkDir(w.Dir)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
|
|
||||||
ignore = make(map[string][]string)
|
ignore = make(map[string][]string)
|
||||||
@ -70,6 +77,8 @@ func (w *Walker) Walk() (files []File, ignore map[string][]string) {
|
|||||||
d := t1.Sub(t0).Seconds()
|
d := t1.Sub(t0).Seconds()
|
||||||
dlog.Printf("Walk in %.02f ms, %.0f files/s", d*1000, float64(len(files))/d)
|
dlog.Printf("Walk in %.02f ms, %.0f files/s", d*1000, float64(len(files))/d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = checkDir(w.Dir)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,3 +281,12 @@ func (w *Walker) ignoreFile(patterns map[string][]string, file string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkDir(dir string) error {
|
||||||
|
if info, err := os.Stat(dir); err != nil {
|
||||||
|
return err
|
||||||
|
} else if !info.IsDir() {
|
||||||
|
return errors.New(dir + ": not a directory")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -27,7 +27,11 @@ func TestWalk(t *testing.T) {
|
|||||||
BlockSize: 128 * 1024,
|
BlockSize: 128 * 1024,
|
||||||
IgnoreFile: ".stignore",
|
IgnoreFile: ".stignore",
|
||||||
}
|
}
|
||||||
files, ignores := w.Walk()
|
files, ignores, err := w.Walk()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if l1, l2 := len(files), len(testdata); l1 != l2 {
|
if l1, l2 := len(files), len(testdata); l1 != l2 {
|
||||||
t.Fatalf("Incorrect number of walked files %d != %d", l1, l2)
|
t.Fatalf("Incorrect number of walked files %d != %d", l1, l2)
|
||||||
@ -54,6 +58,30 @@ func TestWalk(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWalkError(t *testing.T) {
|
||||||
|
w := Walker{
|
||||||
|
Dir: "testdata-missing",
|
||||||
|
BlockSize: 128 * 1024,
|
||||||
|
IgnoreFile: ".stignore",
|
||||||
|
}
|
||||||
|
_, _, err := w.Walk()
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("no error from missing directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
w = Walker{
|
||||||
|
Dir: "testdata/bar",
|
||||||
|
BlockSize: 128 * 1024,
|
||||||
|
IgnoreFile: ".stignore",
|
||||||
|
}
|
||||||
|
_, _, err = w.Walk()
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("no error from non-directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIgnore(t *testing.T) {
|
func TestIgnore(t *testing.T) {
|
||||||
var patterns = map[string][]string{
|
var patterns = map[string][]string{
|
||||||
"": {"t2"},
|
"": {"t2"},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user