Fix issues that may incorrectly interupt directory traversal.

This commit is contained in:
casey langen 2022-12-03 13:13:00 -08:00
parent 921af81536
commit c6ecea564c
2 changed files with 40 additions and 25 deletions

View File

@ -465,10 +465,8 @@ void Indexer::SyncDirectory(
/* start recursive filesystem scan */ /* start recursive filesystem scan */
try { /* boost::filesystem may throw */ try {
/* for each file in the current path... */ /* for each file in the current path... */
boost::filesystem::path path(currentPath); boost::filesystem::path path(currentPath);
boost::filesystem::directory_iterator end; boost::filesystem::directory_iterator end;
boost::filesystem::directory_iterator file(path); boost::filesystem::directory_iterator file(path);
@ -486,28 +484,33 @@ void Indexer::SyncDirectory(
this->SyncDirectory(io, syncRoot, file->path().string(), pathId); this->SyncDirectory(io, syncRoot, file->path().string(), pathId);
} }
else { else {
std::string extension = file->path().extension().string(); try {
for (auto it : this->tagReaders) { std::string extension = file->path().extension().string();
if (it->CanRead(extension.c_str())) { for (auto it : this->tagReaders) {
if (io) { if (it->CanRead(extension.c_str())) {
io->post(boost::bind( if (io) {
&Indexer::ReadMetadataFromFile, io->post(boost::bind(
this, &Indexer::ReadMetadataFromFile,
io, this,
file->path(), io,
pathIdStr)); file->path(),
pathIdStr));
}
else {
this->ReadMetadataFromFile(nullptr, file->path(), pathIdStr);
}
break;
} }
else {
this->ReadMetadataFromFile(nullptr, file->path(), pathIdStr);
}
break;
} }
} }
catch (...) {
/* boost::filesystem may throw trying to stat the file */
}
} }
} }
} }
catch(...) { catch(...) {
/* boost::filesystem may throw trying to open the directory */
} }
} }

View File

@ -76,15 +76,21 @@ static bool hasSubdirectories(
directory_iterator file(p); directory_iterator file(p);
while (file != end) { while (file != end) {
if (is_directory(file->status())) { try {
if (showDotfiles || file->path().leaf().string()[0] != '.') { if (is_directory(file->status())) {
return true; if (showDotfiles || file->path().leaf().string()[0] != '.') {
return true;
}
} }
} }
catch (...) {
/* may throw trying to stat the file */
}
++file; ++file;
} }
} }
catch (...) { catch (...) {
/* may throw trying to open the dir */
} }
return false; return false;
@ -102,16 +108,22 @@ static void buildDirectoryList(
directory_iterator file(p); directory_iterator file(p);
while (file != end) { while (file != end) {
if (is_directory(file->status())) { try {
std::string leaf = file->path().leaf().string(); if (is_directory(file->status())) {
if (showDotfiles || leaf[0] != '.') { std::string leaf = file->path().leaf().string();
target.push_back(leaf); if (showDotfiles || leaf[0] != '.') {
target.push_back(leaf);
}
} }
} }
catch (...) {
/* may throw trying to stat the file */
}
++file; ++file;
} }
} }
catch (...) { catch (...) {
/* may throw trying to open the directory */
} }
try { try {