From 57fc0eb5b1ffc7c58b7e998e09c78ef86bb69e4c Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 8 Mar 2015 17:33:41 +0000 Subject: [PATCH] Make sure we start scanning at an indexed location (fixes #1399) --- internal/model/model.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/model/model.go b/internal/model/model.go index 9721f8ccc..43ecc46b8 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -1146,6 +1146,7 @@ func (m *Model) ScanFolder(folder string) error { } func (m *Model) ScanFolderSub(folder, sub string) error { + sub = osutil.NativeFilename(sub) if p := filepath.Clean(filepath.Join(folder, sub)); !strings.HasPrefix(p, folder) { return errors.New("invalid subpath") } @@ -1162,6 +1163,18 @@ func (m *Model) ScanFolderSub(folder, sub string) error { _ = ignores.Load(filepath.Join(folderCfg.Path, ".stignore")) // Ignore error, there might not be an .stignore + // Required to make sure that we start indexing at a directory we're already + // aware off. + for sub != "" { + if _, ok = fs.Get(protocol.LocalDeviceID, sub); ok { + break + } + sub = filepath.Dir(sub) + if sub == "." || sub == string(filepath.Separator) { + sub = "" + } + } + w := &scanner.Walker{ Dir: folderCfg.Path, Sub: sub,