[DB] Properly handle out-of-root media files

This commit is contained in:
emeric
2015-09-19 13:43:23 +02:00
parent 14481d1e77
commit ac1d32ddac
2 changed files with 21 additions and 3 deletions
+20 -3
View File
@@ -72,7 +72,7 @@ isFileSupported(const boost::filesystem::path& file, const std::vector<boost::fi
boost::filesystem::path fileExtension = file.extension();
for (auto extension : extensions)
for (auto& extension : extensions)
{
if (extension == fileExtension)
return true;
@@ -93,6 +93,22 @@ getRootDirectoriesByType(Wt::Dbo::Session& session, Database::MediaDirectory::Ty
return res;
}
bool
isPathInParentPath(const boost::filesystem::path& path, const boost::filesystem::path& parentPath)
{
boost::filesystem::path curPath = path;
while (curPath.has_parent_path())
{
curPath = curPath.parent_path();
if (curPath == parentPath)
return true;
}
return false;
}
} // namespace
@@ -607,10 +623,11 @@ Updater::checkFile(const boost::filesystem::path& p, const std::vector<boost::fi
}
else
{
bool foundRoot = false;
for (auto rootDir : rootDirs)
for (auto& rootDir : rootDirs)
{
if (p.string().find( rootDir.string() ) != std::string::npos)
if (isPathInParentPath(p, rootDir))
{
foundRoot = true;
break;