mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-09 17:53:59 +00:00
Mark repos with missing dir as invalid on startup (fixes #311)
This commit is contained in:
parent
964c903a68
commit
5a98f4e47c
@ -279,11 +279,28 @@ func main() {
|
|||||||
|
|
||||||
m := model.NewModel(confDir, &cfg, "syncthing", Version)
|
m := model.NewModel(confDir, &cfg, "syncthing", Version)
|
||||||
|
|
||||||
for _, repo := range cfg.Repositories {
|
nextRepo:
|
||||||
|
for i, repo := range cfg.Repositories {
|
||||||
if repo.Invalid != "" {
|
if repo.Invalid != "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.Directory = expandTilde(repo.Directory)
|
repo.Directory = expandTilde(repo.Directory)
|
||||||
|
|
||||||
|
// Safety check. If the cached index contains files but the repository
|
||||||
|
// doesn't exist, we have a problem. We would assume that all files
|
||||||
|
// have been deleted which might not be the case, so abort instead.
|
||||||
|
|
||||||
|
id := fmt.Sprintf("%x", sha1.Sum([]byte(repo.Directory)))
|
||||||
|
idxFile := filepath.Join(confDir, id+".idx.gz")
|
||||||
|
if _, err := os.Stat(idxFile); err == nil {
|
||||||
|
if fi, err := os.Stat(repo.Directory); err != nil || !fi.IsDir() {
|
||||||
|
cfg.Repositories[i].Invalid = "repo directory missing"
|
||||||
|
continue nextRepo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureDir(repo.Directory, -1)
|
||||||
m.AddRepo(repo)
|
m.AddRepo(repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,29 +344,6 @@ func main() {
|
|||||||
|
|
||||||
l.Infoln("Populating repository index")
|
l.Infoln("Populating repository index")
|
||||||
m.LoadIndexes(confDir)
|
m.LoadIndexes(confDir)
|
||||||
|
|
||||||
for _, repo := range cfg.Repositories {
|
|
||||||
if repo.Invalid != "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
dir := expandTilde(repo.Directory)
|
|
||||||
|
|
||||||
// Safety check. If the cached index contains files but the repository
|
|
||||||
// doesn't exist, we have a problem. We would assume that all files
|
|
||||||
// have been deleted which might not be the case, so abort instead.
|
|
||||||
|
|
||||||
if files, _, _ := m.LocalSize(repo.ID); files > 0 {
|
|
||||||
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
|
|
||||||
l.Warnf("Configured repository %q has index but directory %q is missing; not starting.", repo.ID, repo.Directory)
|
|
||||||
l.Fatalf("Ensure that directory is present or remove repository from configuration.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that repository directories exist for newly configured repositories.
|
|
||||||
ensureDir(dir, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
m.CleanRepos()
|
m.CleanRepos()
|
||||||
m.ScanRepos()
|
m.ScanRepos()
|
||||||
m.SaveIndexes(confDir)
|
m.SaveIndexes(confDir)
|
||||||
|
Loading…
Reference in New Issue
Block a user