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 */
try { /* boost::filesystem may throw */
try {
/* for each file in the current path... */
boost::filesystem::path path(currentPath);
boost::filesystem::directory_iterator end;
boost::filesystem::directory_iterator file(path);
@ -486,28 +484,33 @@ void Indexer::SyncDirectory(
this->SyncDirectory(io, syncRoot, file->path().string(), pathId);
}
else {
std::string extension = file->path().extension().string();
for (auto it : this->tagReaders) {
if (it->CanRead(extension.c_str())) {
if (io) {
io->post(boost::bind(
&Indexer::ReadMetadataFromFile,
this,
io,
file->path(),
pathIdStr));
try {
std::string extension = file->path().extension().string();
for (auto it : this->tagReaders) {
if (it->CanRead(extension.c_str())) {
if (io) {
io->post(boost::bind(
&Indexer::ReadMetadataFromFile,
this,
io,
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(...) {
/* boost::filesystem may throw trying to open the directory */
}
}

View File

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