Skipping directories containing a .lmsignore file. fix #120
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
<div class="col-lg-9">
|
||||
${media-directory}
|
||||
${media-directory-info class="help-block"}
|
||||
<span class="help-block">${tr:Lms.Admin.Database.path-help}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<message id="Lms.Admin.Database.menu-database"><i class="fa fa-fw fa-database" aria-hidden="true"></i> Music collection</message>
|
||||
<message id="Lms.Admin.Database.never">Never</message>
|
||||
<message id="Lms.Admin.Database.path">Media root directory</message>
|
||||
<message id="Lms.Admin.Database.path-help">Directories containing a <code>.lmsignore</code> file are skipped</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type">Recommendation engine</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type.clusters">Tags based</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type.features">Audio analysis based</message>
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<message id="Lms.Admin.Database.menu-database"><i class="fa fa-fw fa-database" aria-hidden="true"></i> Collection de musiques</message>
|
||||
<message id="Lms.Admin.Database.never">Jamais</message>
|
||||
<message id="Lms.Admin.Database.path">Dossier racine des fichiers de musique</message>
|
||||
<message id="Lms.Admin.Database.path-help">Les dossiers contenant un fichier <code>.lmsignore</code> sont ignorés</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type">Moteur de recommandation</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type.clusters">Basé sur les tags</message>
|
||||
<message id="Lms.Admin.Database.recommendation-engine-type.features">Basé sur l'analyse audio</message>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user