Skipping directories containing a .lmsignore file. fix #120

This commit is contained in:
emeric
2021-03-21 14:32:26 +01:00
parent b741978e33
commit 260e5833d3
6 changed files with 28 additions and 8 deletions
+11 -5
View File
@@ -43,6 +43,8 @@ using namespace Database;
namespace {
const std::filesystem::path excludeDirFileName {".lmsignore"};
Wt::WDate
getNextMonday(Wt::WDate current)
{
@@ -74,7 +76,7 @@ isFileSupported(const std::filesystem::path& file, const std::unordered_set<std:
}
bool
isPathInParentPath(const std::filesystem::path& path, const std::filesystem::path& parentPath)
isPathInMediaDirectory(const std::filesystem::path& path, const std::filesystem::path& rootPath)
{
std::filesystem::path curPath = path;
@@ -82,7 +84,11 @@ isPathInParentPath(const std::filesystem::path& path, const std::filesystem::pat
{
curPath = curPath.parent_path();
if (curPath == parentPath)
std::error_code ec;
if (std::filesystem::exists(curPath / excludeDirFileName, ec))
return false;
if (curPath == rootPath)
return true;
}
@@ -434,7 +440,7 @@ Scanner::countAllFiles(ScanStats& stats)
}
return true;
});
}, excludeDirFileName);
notifyInProgress(stepStats);
}
@@ -855,7 +861,7 @@ Scanner::scanMediaDirectory(const std::filesystem::path& mediaDirectory, bool fo
}
return true;
});
}, excludeDirFileName);
notifyInProgress(stepStats);
}
@@ -875,7 +881,7 @@ checkFile(const std::filesystem::path& p, const std::filesystem::path& mediaDire
return false;
}
if (!isPathInParentPath(p, mediaDirectory))
if (!isPathInMediaDirectory(p, mediaDirectory))
{
LMS_LOG(DBUPDATER, INFO) << "Removing '" << p.string() << "': out of media directory";
return false;
+13 -2
View File
@@ -79,7 +79,7 @@ getLastWriteTime(const std::filesystem::path& file)
}
bool
exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb)
exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb, const std::filesystem::path& excludeDirFileName)
{
std::error_code ec;
std::filesystem::directory_iterator itPath {directory, std::filesystem::directory_options::follow_directory_symlink, ec};
@@ -90,6 +90,17 @@ exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool
return true; // try to continue exploring anyway
}
if (!excludeDirFileName.empty())
{
const std::filesystem::path excludePath {directory / excludeDirFileName};
if (std::filesystem::exists(excludePath, ec))
{
LMS_LOG(DBUPDATER, DEBUG) << "Found '" << excludePath.string() << "': skipping directory";
return true;
}
}
std::filesystem::directory_iterator itEnd;
while (itPath != itEnd)
{
@@ -108,7 +119,7 @@ exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool
else if (std::filesystem::is_directory(*itPath, ec))
{
if (!ec)
continueExploring = exploreFilesRecursive(*itPath, cb);
continueExploring = exploreFilesRecursive(*itPath, cb, excludeDirFileName);
else
continueExploring = cb(ec, *itPath);
}
+1 -1
View File
@@ -36,7 +36,7 @@ bool ensureDirectory(const std::filesystem::path& dir);
Wt::WDateTime getLastWriteTime(const std::filesystem::path& dir);
// returns false if aborted by user
bool exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb);
bool exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb, const std::filesystem::path& excludeDirFileName = {});
namespace std
{