@@ -628,30 +628,29 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
628
628
string today (ymd);
629
629
DLOG (INFO) << " today: " << today;
630
630
631
- // Make sure we have sufficient permissions on the scanned directories.
632
- // E.g. on Android, there's no write permission on the cwd.
633
- vector<string> dirs;
634
- for (auto & dir : google::GetLoggingDirectories ()) {
635
- auto perms = fs::status (dir).permissions ();
636
- if ((perms & (fs::perms::owner_write | fs::perms::group_write |
637
- fs::perms::others_write)) != fs::perms::none) {
638
- dirs.push_back (dir);
639
- }
640
- }
631
+ vector<string> dirs (google::GetLoggingDirectories ());
632
+
641
633
DLOG (INFO) << " scanning " << dirs.size () << " temp directory for log files." ;
642
634
643
635
int removed = 0 ;
644
636
for (const auto & dir : dirs) {
645
637
vector<path> files;
646
638
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 ());
639
+ try {
640
+ // preparing files
641
+ for (const auto & entry : fs::directory_iterator (dir)) {
642
+ const string& file_name (entry.path ().filename ().string ());
643
+ if (entry.is_regular_file () && !entry.is_symlink () &&
644
+ boost::starts_with (file_name, " rime." ) &&
645
+ !boost::contains (file_name, today)) {
646
+ files.push_back (entry.path ());
647
+ }
654
648
}
649
+ } catch (const fs::filesystem_error& ex) {
650
+ // Catch error to skip up when we have no sufficient permissions.
651
+ // E.g. on Android, there's no read permission on the cwd.
652
+ LOG (WARNING) << " couldn't list directory '" << dir << " ': " << ex.what ();
653
+ continue ;
655
654
}
656
655
// remove files
657
656
for (const auto & file : files) {
0 commit comments