Skip to content

Commit

Permalink
fix(glog): no read permission on the cwd on Android (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokapsing committed Mar 4, 2024
1 parent 33ce245 commit edee320
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/rime/lever/deployment_tasks.cc
Expand Up @@ -628,30 +628,29 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
string today(ymd);
DLOG(INFO) << "today: " << today;

// Make sure we have sufficient permissions on the scanned directories.
// E.g. on Android, there's no write permission on the cwd.
vector<string> dirs;
for (auto& dir : google::GetLoggingDirectories()) {
auto perms = fs::status(dir).permissions();
if ((perms & (fs::perms::owner_write | fs::perms::group_write |
fs::perms::others_write)) != fs::perms::none) {
dirs.push_back(dir);
}
}
vector<string> dirs(google::GetLoggingDirectories());

DLOG(INFO) << "scanning " << dirs.size() << " temp directory for log files.";

int removed = 0;
for (const auto& dir : dirs) {
vector<path> files;
DLOG(INFO) << "temp directory: " << dir;
// preparing files
for (const auto& entry : fs::directory_iterator(dir)) {
const string& file_name(entry.path().filename().string());
if (entry.is_regular_file() && !entry.is_symlink() &&
boost::starts_with(file_name, "rime.") &&
!boost::contains(file_name, today)) {
files.push_back(entry.path());
try {
// preparing files
for (const auto& entry : fs::directory_iterator(dir)) {
const string& file_name(entry.path().filename().string());
if (entry.is_regular_file() && !entry.is_symlink() &&
boost::starts_with(file_name, "rime.") &&
!boost::contains(file_name, today)) {
files.push_back(entry.path());
}
}
} catch (const fs::filesystem_error& ex) {
// Catch error to skip up when we have no sufficient permissions.
// E.g. on Android, there's no read permission on the cwd.
LOG(WARNING) << "couldn't list directory '" << dir << "': " << ex.what();
continue;
}
// remove files
for (const auto& file : files) {
Expand Down

0 comments on commit edee320

Please sign in to comment.