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

set log filename extension and avoid deleting incorrect files #838

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
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
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
Loading