From 022121931aaa9f422ed4cc52fd4167b7a7c78973 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 4 Nov 2020 14:35:45 +0100 Subject: [PATCH] Fix real-time indexer indexing nothing in rare case where topdirs was /, because of incorrect path/skippedPaths test --- src/index/fsindexer.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index 2a270871..97a4d461 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 J.F.Dockes +/* Copyright (C) 2009-2020 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -252,9 +252,8 @@ bool FsIndexer::index(int flags) return true; } -static bool matchesSkipped(const vector& tdl, - FsTreeWalker& walker, - const string& path) +static bool matchesSkipped( + const vector& tdl, FsTreeWalker& walker, const string& path) { // Check path against topdirs and skippedPaths. We go up the // ancestors until we find either a topdirs or a skippedPaths @@ -263,16 +262,17 @@ static bool matchesSkipped(const vector& tdl, // config). This matches what happens during the normal fs tree // walk. string canonpath = path_canon(path); + string mpath = canonpath; string topdir; - while (!path_isroot(mpath)) { // we assume root not in skipped paths. - for (vector::const_iterator it = tdl.begin(); - it != tdl.end(); it++) { + for (;;) { // Used to test not root here, but root may be in topdirs ! + + for (const auto tdlent : tdl) { // the topdirs members are already canonized. - LOGDEB2("matchesSkipped: comparing ancestor [" << mpath << - "] to topdir [" << *it << "]\n"); - if (!mpath.compare(*it)) { - topdir = *it; + LOGDEB1("matchesSkipped: comparing ancestor [" << mpath << + "] to topdir [" << tdlent << "]\n"); + if (mpath == tdlent) { + topdir = tdlent; goto goodpath; } } @@ -282,6 +282,11 @@ static bool matchesSkipped(const vector& tdl, return true; } + if (path_isroot(mpath)) { + break; + } + + // Compute father string::size_type len = mpath.length(); mpath = path_getfather(mpath); // getfather normally returns a path ending with /, canonic @@ -296,7 +301,9 @@ static bool matchesSkipped(const vector& tdl, "] did not shorten\n"); return true; } + } + // We get there if neither topdirs nor skippedPaths tests matched LOGDEB("FsIndexer::indexFiles: skipping [" << path << "] (ntd)\n"); return true;