mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
parent
3eb000fa60
commit
2091e12e82
@ -522,13 +522,6 @@ nextFolder:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the folder and update the local model before establishing any
|
|
||||||
// connections to other devices.
|
|
||||||
|
|
||||||
m.CleanFolders()
|
|
||||||
l.Infoln("Performing initial folder scan")
|
|
||||||
m.ScanFolders()
|
|
||||||
|
|
||||||
// Remove all .idx* files that don't belong to an active folder.
|
// Remove all .idx* files that don't belong to an active folder.
|
||||||
|
|
||||||
validIndexes := make(map[string]bool)
|
validIndexes := make(map[string]bool)
|
||||||
|
@ -171,10 +171,9 @@ func (m *Model) StartFolderRW(folder string) {
|
|||||||
// pull in any external changes.
|
// pull in any external changes.
|
||||||
func (m *Model) StartFolderRO(folder string) {
|
func (m *Model) StartFolderRO(folder string) {
|
||||||
intv := time.Duration(m.folderCfgs[folder].RescanIntervalS) * time.Second
|
intv := time.Duration(m.folderCfgs[folder].RescanIntervalS) * time.Second
|
||||||
|
initialScanCompleted := false
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(intv)
|
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(m, "rescan", folder)
|
l.Debugln(m, "rescan", folder)
|
||||||
}
|
}
|
||||||
@ -185,6 +184,11 @@ func (m *Model) StartFolderRO(folder string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.setState(folder, FolderIdle)
|
m.setState(folder, FolderIdle)
|
||||||
|
if !initialScanCompleted {
|
||||||
|
l.Infoln("Completed initial scan (ro) of folder", folder)
|
||||||
|
initialScanCompleted = true
|
||||||
|
}
|
||||||
|
time.Sleep(intv)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -959,29 +963,6 @@ func (m *Model) ScanFolders() {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) CleanFolders() {
|
|
||||||
m.fmut.RLock()
|
|
||||||
var dirs = make([]string, 0, len(m.folderCfgs))
|
|
||||||
for _, cfg := range m.folderCfgs {
|
|
||||||
dirs = append(dirs, cfg.Path)
|
|
||||||
}
|
|
||||||
m.fmut.RUnlock()
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(len(dirs))
|
|
||||||
for _, dir := range dirs {
|
|
||||||
w := &scanner.Walker{
|
|
||||||
Dir: dir,
|
|
||||||
TempNamer: defTempNamer,
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
w.CleanTempFiles()
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Model) ScanFolder(folder string) error {
|
func (m *Model) ScanFolder(folder string) error {
|
||||||
return m.ScanFolderSub(folder, "")
|
return m.ScanFolderSub(folder, "")
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (p *Puller) Serve() {
|
|||||||
p.stop = make(chan struct{})
|
p.stop = make(chan struct{})
|
||||||
|
|
||||||
pullTimer := time.NewTimer(checkPullIntv)
|
pullTimer := time.NewTimer(checkPullIntv)
|
||||||
scanTimer := time.NewTimer(p.scanIntv)
|
scanTimer := time.NewTimer(time.Millisecond) // The first scan should be done immediately.
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
pullTimer.Stop()
|
pullTimer.Stop()
|
||||||
@ -84,6 +84,9 @@ func (p *Puller) Serve() {
|
|||||||
// Clean out old temporaries before we start pulling
|
// Clean out old temporaries before we start pulling
|
||||||
p.clean()
|
p.clean()
|
||||||
|
|
||||||
|
// We don't start pulling files until a scan has been completed.
|
||||||
|
initialScanCompleted := false
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -96,6 +99,10 @@ loop:
|
|||||||
// repeatable benchmark of how long it takes to sync a change from
|
// repeatable benchmark of how long it takes to sync a change from
|
||||||
// device A to device B, so we have something to work against.
|
// device A to device B, so we have something to work against.
|
||||||
case <-pullTimer.C:
|
case <-pullTimer.C:
|
||||||
|
if !initialScanCompleted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// RemoteLocalVersion() is a fast call, doesn't touch the database.
|
// RemoteLocalVersion() is a fast call, doesn't touch the database.
|
||||||
curVer := p.model.RemoteLocalVersion(p.folder)
|
curVer := p.model.RemoteLocalVersion(p.folder)
|
||||||
if curVer == prevVer {
|
if curVer == prevVer {
|
||||||
@ -163,6 +170,10 @@ loop:
|
|||||||
}
|
}
|
||||||
p.model.setState(p.folder, FolderIdle)
|
p.model.setState(p.folder, FolderIdle)
|
||||||
scanTimer.Reset(p.scanIntv)
|
scanTimer.Reset(p.scanIntv)
|
||||||
|
if !initialScanCompleted {
|
||||||
|
l.Infoln("Completed initial scan (rw) of folder", p.folder)
|
||||||
|
initialScanCompleted = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,6 @@ func (w *Walker) Walk() (chan protocol.FileInfo, error) {
|
|||||||
return hashedFiles, nil
|
return hashedFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanTempFiles removes all files that match the temporary filename pattern.
|
|
||||||
func (w *Walker) CleanTempFiles() {
|
|
||||||
filepath.Walk(w.Dir, w.cleanTempFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFunc {
|
func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFunc {
|
||||||
return func(p string, info os.FileInfo, err error) error {
|
return func(p string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,16 +176,6 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Walker) cleanTempFile(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.Mode()&os.ModeType == 0 && w.TempNamer.IsTemporary(path) {
|
|
||||||
os.Remove(path)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkDir(dir string) error {
|
func checkDir(dir string) error {
|
||||||
if info, err := os.Lstat(dir); err != nil {
|
if info, err := os.Lstat(dir); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user