Skip to content

Commit a407965

Browse files
authored
Merge branch 'rime:master' into master
2 parents ad69ffb + f6dd300 commit a407965

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/rime/lever/deployment_tasks.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
636636
// avoid iteration on non-existing directory, which may cause error
637637
if (!fs::exists(fs::path(dir)))
638638
continue;
639-
vector<path> files;
639+
vector<path> files_to_remove;
640+
set<path> files_in_use;
640641
DLOG(INFO) << "temp directory: " << dir;
641642
try {
642643
// preparing files
@@ -646,7 +647,14 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
646647
boost::starts_with(file_name, app_name) &&
647648
boost::ends_with(file_name, ".log") &&
648649
!boost::contains(file_name, today)) {
649-
files.push_back(entry.path());
650+
files_to_remove.push_back(entry.path());
651+
} else if (entry.is_symlink()) {
652+
auto target = fs::read_symlink(entry.path());
653+
const string& target_file_name(target.filename().u8string());
654+
if (boost::starts_with(target_file_name, app_name) &&
655+
boost::ends_with(target_file_name, ".log")) {
656+
files_in_use.insert(target);
657+
}
650658
}
651659
}
652660
} catch (const fs::filesystem_error& ex) {
@@ -656,7 +664,9 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
656664
continue;
657665
}
658666
// remove files
659-
for (const auto& file : files) {
667+
for (const auto& file : files_to_remove) {
668+
if (files_in_use.find(file.filename()) != files_in_use.end())
669+
continue;
660670
try {
661671
DLOG(INFO) << "removing log file '" << file.filename() << "'.";
662672
// ensure write permission

0 commit comments

Comments
 (0)