Skip to content

Commit

Permalink
set log filename extension and avoid deleting incorrect files (#838)
Browse files Browse the repository at this point in the history
* set log filename extension ".log"

* avoid deleting non-log file or not log files of current app

---------

Co-authored-by: 居戎氏 <chen.sst@gmail.com>
  • Loading branch information
fxliang and lotem authored Mar 6, 2024
1 parent 3019e5f commit a4ed799
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/rime/deployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Deployer : public Messenger {
string distribution_name;
string distribution_code_name;
string distribution_version;
string app_name;
// }

RIME_API Deployer();
Expand Down
4 changes: 3 additions & 1 deletion src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
DLOG(INFO) << "scanning " << dirs.size() << " temp directory for log files.";

int removed = 0;
const string& app_name = deployer->app_name;
for (const auto& dir : dirs) {
// avoid iteration on non-existing directory, which may cause error
if (!fs::exists(fs::path(dir)))
Expand All @@ -644,7 +645,8 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
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::starts_with(file_name, app_name) &&
boost::ends_with(file_name, ".log") &&
!boost::contains(file_name, today)) {
files.push_back(entry.path());
}
Expand Down
3 changes: 3 additions & 0 deletions src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ RIME_API void SetupDeployer(RimeTraits* traits) {
deployer.distribution_code_name = traits->distribution_code_name;
if (PROVIDED(traits, distribution_version))
deployer.distribution_version = traits->distribution_version;
if (PROVIDED(traits, app_name))
deployer.app_name = traits->app_name;
if (PROVIDED(traits, prebuilt_data_dir))
deployer.prebuilt_data_dir = path(traits->prebuilt_data_dir);
else
Expand All @@ -82,6 +84,7 @@ RIME_API void SetupLogging(const char* app_name,
FLAGS_log_dir = log_dir;
}
}
google::SetLogFilenameExtension(".log");
// Do not allow other users to read/write log files created by current
// process.
FLAGS_logfile_mode = 0600;
Expand Down

0 comments on commit a4ed799

Please sign in to comment.