Skip to content

Commit

Permalink
Fix file existence check to handle 'No such file or directory' error …
Browse files Browse the repository at this point in the history
…properly
  • Loading branch information
umegane committed Aug 29, 2024
1 parent 096c67d commit f90b083
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/limestone/rotation_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ void rotation_task::rotate() {
boost::system::error_code error;
bool result = boost::filesystem::exists(lc->file_path(), error);
if (error) {
LOG_LP(ERROR) << "Failed to check if file exists: " << lc->file_path() << ", error_code: " << error.message();
throw std::runtime_error("Failed to check if file exists: " + lc->file_path().string());
}
if (!result) {
LOG_LP(INFO) << "File does not exist, skipping: " << lc->file_path();
continue; // skip if file does not exist
if (error == boost::system::errc::no_such_file_or_directory || !result) {
LOG_LP(INFO) << "File does not exist, skipping: " << lc->file_path();
continue;
} else {

Check warning on line 76 in src/limestone/rotation_task.cpp

View workflow job for this annotation

GitHub Actions / Clang-Tidy

llvm-else-after-return,readability-else-after-return

do not use 'else' after 'continue'
// For any other errors
LOG_LP(ERROR) << "Failed to check if file exists: " << lc->file_path() << ", error_code: " << error.message();
throw std::runtime_error("Failed to check if file exists: " + lc->file_path().string());
}
}

// The following code may seem necessary at first glance, but there is a possibility
// that files could be appended to before the rotation is complete.
// In that case, skipping them could result in missing files that should be processed.
Expand Down

0 comments on commit f90b083

Please sign in to comment.