Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(glog): no read permission on the cwd on Android #835

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
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());
}
}
mokapsing marked this conversation as resolved.
Show resolved Hide resolved
} 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
Loading