Skip to content

Commit

Permalink
avoid deleting non-log file or not log files of current app
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Mar 6, 2024
1 parent d71b6ee commit 4b09fe4
Show file tree
Hide file tree
Showing 3 changed files with 6 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 @@ -39,6 +39,7 @@ class Deployer : public Messenger {
path sync_dir;
string user_id;
string distribution_name;
string app_name;
string distribution_code_name;
string distribution_version;
// }
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;
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
2 changes: 2 additions & 0 deletions src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ RIME_API void SetupDeployer(RimeTraits* traits) {
deployer.user_data_dir = path(traits->user_data_dir);
if (PROVIDED(traits, distribution_name))
deployer.distribution_name = traits->distribution_name;
if (PROVIDED(traits, app_name))
deployer.app_name = traits->app_name;
if (PROVIDED(traits, distribution_code_name))
deployer.distribution_code_name = traits->distribution_code_name;
if (PROVIDED(traits, distribution_version))
Expand Down

0 comments on commit 4b09fe4

Please sign in to comment.