Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployment_tasks): do not remove log files in use #913

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
// avoid iteration on non-existing directory, which may cause error
if (!fs::exists(fs::path(dir)))
continue;
vector<path> files;
vector<path> files_to_remove;
set<path> files_in_use;
DLOG(INFO) << "temp directory: " << dir;
try {
// preparing files
Expand All @@ -646,7 +647,14 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
boost::starts_with(file_name, app_name) &&
boost::ends_with(file_name, ".log") &&
!boost::contains(file_name, today)) {
files.push_back(entry.path());
files_to_remove.push_back(entry.path());
} else if (entry.is_symlink()) {
auto target = fs::read_symlink(entry.path());
const string& target_file_name(target.filename().u8string());
if (boost::starts_with(target_file_name, app_name) &&
boost::ends_with(target_file_name, ".log")) {
files_in_use.insert(target);
}
}
}
} catch (const fs::filesystem_error& ex) {
Expand All @@ -656,7 +664,9 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
continue;
}
// remove files
for (const auto& file : files) {
for (const auto& file : files_to_remove) {
if (files_in_use.find(file.filename()) != files_in_use.end())
continue;
try {
DLOG(INFO) << "removing log file '" << file.filename() << "'.";
// ensure write permission
Expand Down