Skip to content

Commit edee320

Browse files
authored
fix(glog): no read permission on the cwd on Android (#835)
1 parent 33ce245 commit edee320

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/rime/lever/deployment_tasks.cc

+16-17
Original file line numberDiff line numberDiff line change
@@ -628,30 +628,29 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
628628
string today(ymd);
629629
DLOG(INFO) << "today: " << today;
630630

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+
641633
DLOG(INFO) << "scanning " << dirs.size() << " temp directory for log files.";
642634

643635
int removed = 0;
644636
for (const auto& dir : dirs) {
645637
vector<path> files;
646638
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+
}
654648
}
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;
655654
}
656655
// remove files
657656
for (const auto& file : files) {

0 commit comments

Comments
 (0)