@@ -636,7 +636,8 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
636
636
// avoid iteration on non-existing directory, which may cause error
637
637
if (!fs::exists (fs::path (dir)))
638
638
continue ;
639
- vector<path> files;
639
+ vector<path> files_to_remove;
640
+ set<path> files_in_use;
640
641
DLOG (INFO) << " temp directory: " << dir;
641
642
try {
642
643
// preparing files
@@ -646,7 +647,14 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
646
647
boost::starts_with (file_name, app_name) &&
647
648
boost::ends_with (file_name, " .log" ) &&
648
649
!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
+ }
650
658
}
651
659
}
652
660
} catch (const fs::filesystem_error& ex) {
@@ -656,7 +664,9 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
656
664
continue ;
657
665
}
658
666
// 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 ;
660
670
try {
661
671
DLOG (INFO) << " removing log file '" << file.filename () << " '." ;
662
672
// ensure write permission
0 commit comments