FIX: cancel remove if log file is opened by other program

Change-Id: I725b03a82af292f9dc81d5f5500773600346c218
(cherry picked from commit f72f4044c2d8a010d1129b4eba1220c20bdf050b)
(cherry picked from commit 3a4daa90b526e8970913311fe9bd314b865c92dd)
This commit is contained in:
tao.jin 2022-11-07 14:42:30 +08:00 committed by Lane.Wei
parent 4d90cc5f80
commit 9e561a3887

View file

@ -1155,7 +1155,12 @@ void GUI_App::post_init()
while (files_vec.size() > LOG_FILES_MAX_NUM) {
auto full_path = log_folder / boost::filesystem::path(files_vec[files_vec.size() - 1].second);
BOOST_LOG_TRIVIAL(info) << "delete log file over " << LOG_FILES_MAX_NUM << ", filename: "<< files_vec[files_vec.size() - 1].second;
boost::filesystem::remove(full_path);
try {
boost::filesystem::remove(full_path);
}
catch (const std::exception& ex) {
BOOST_LOG_TRIVIAL(error) << "failed to delete log file: "<< files_vec[files_vec.size() - 1].second << ". Error: " << ex.what();
}
files_vec.pop_back();
}
}