@@ -641,19 +641,26 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
641
641
DLOG (INFO) << " scanning " << dirs.size () << " temp directory for log files." ;
642
642
643
643
int removed = 0 ;
644
- for (auto i = dirs.cbegin (); i != dirs.cend (); ++i) {
645
- DLOG (INFO) << " temp directory: " << *i;
646
- for (fs::directory_iterator j (*i), end; j != end; ++j) {
647
- fs::path entry (j->path ());
648
- string file_name (entry.filename ().string ());
644
+ for (const auto & dir : dirs) {
645
+ vector<fs::path> files;
646
+ DLOG (INFO) << " temp directory: " << dir;
647
+ // preparing files
648
+ for (const auto & entry : fs::directory_iterator (dir)) {
649
+ const string& file_name (entry.path ().filename ().string ());
650
+ if (entry.is_regular_file () && !entry.is_symlink () &&
651
+ boost::starts_with (file_name, " rime." ) &&
652
+ !boost::contains (file_name, today)) {
653
+ files.push_back (entry.path ());
654
+ }
655
+ }
656
+ // remove files
657
+ for (const auto & file : files) {
649
658
try {
650
- if (fs::is_regular_file (entry) && !fs::is_symlink (entry) &&
651
- boost::starts_with (file_name, " rime." ) &&
652
- !boost::contains (file_name, today)) {
653
- DLOG (INFO) << " removing log file '" << file_name << " '." ;
654
- fs::remove (entry);
655
- ++removed;
656
- }
659
+ DLOG (INFO) << " removing log file '" << file.filename () << " '." ;
660
+ // ensure write permission
661
+ fs::permissions (file, fs::perms::owner_write);
662
+ fs::remove (file);
663
+ ++removed;
657
664
} catch (const fs::filesystem_error& ex) {
658
665
LOG (ERROR) << ex.what ();
659
666
success = false ;
0 commit comments