Skip to content

Commit

Permalink
chore: use path::u8string for filename comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Mar 28, 2024
1 parent 060555c commit 4d8bb87
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Simplifier::Simplifier(const Ticket& ticket)
void Simplifier::Initialize() {
initialized_ = true; // no retry
path opencc_config_path = path(opencc_config_);
if (opencc_config_path.extension().string() == ".ini") {
if (opencc_config_path.extension().u8string() == ".ini") {
LOG(ERROR) << "please upgrade opencc_config to an opencc 1.0 config file.";
return;
}
Expand Down
14 changes: 7 additions & 7 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ bool DetectModifications::Run(Deployer* deployer) {
for (fs::directory_iterator iter(p), end; iter != end; ++iter) {
path entry(iter->path());
if (fs::is_regular_file(fs::canonical(entry)) &&
entry.extension().string() == ".yaml" &&
entry.filename().string() != "user.yaml") {
entry.extension().u8string() == ".yaml" &&
entry.filename().u8string() != "user.yaml") {
last_modified =
(std::max)(last_modified,
filesystem::to_time_t(fs::last_write_time(entry)));
Expand Down Expand Up @@ -458,7 +458,7 @@ bool PrebuildAllSchemas::Run(Deployer* deployer) {
for (fs::directory_iterator iter(shared_data_path), end; iter != end;
++iter) {
path entry(iter->path());
if (boost::ends_with(entry.filename().string(), ".schema.yaml")) {
if (boost::ends_with(entry.filename().u8string(), ".schema.yaml")) {
the<DeploymentTask> t(new SchemaUpdate(entry));
if (!t->Run(deployer))
success = false;
Expand Down Expand Up @@ -523,7 +523,7 @@ bool UserDictSync::Run(Deployer* deployer) {
}

static bool IsCustomizedCopy(const path& file_path) {
auto file_name = file_path.filename().string();
auto file_name = file_path.filename().u8string();
if (boost::ends_with(file_name, ".yaml") &&
!boost::ends_with(file_name, ".custom.yaml")) {
Config config;
Expand All @@ -550,7 +550,7 @@ bool BackupConfigFiles::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_extension = entry.extension().string();
auto file_extension = entry.extension().u8string();
bool is_yaml_file = file_extension == ".yaml";
bool is_text_file = file_extension == ".txt";
if (!is_yaml_file && !is_text_file)
Expand Down Expand Up @@ -590,7 +590,7 @@ bool CleanupTrash::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_name = entry.filename().string();
auto file_name = entry.filename().u8string();
if (file_name == "rime.log" || boost::ends_with(file_name, ".bin") ||
boost::ends_with(file_name, ".reverse.kct") ||
boost::ends_with(file_name, ".userdb.kct.old") ||
Expand Down Expand Up @@ -643,7 +643,7 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
try {
// preparing files
for (const auto& entry : fs::directory_iterator(dir)) {
const string& file_name(entry.path().filename().string());
const string& file_name(entry.path().filename().u8string());
if (entry.is_regular_file() && !entry.is_symlink() &&
boost::starts_with(file_name, app_name) &&
boost::ends_with(file_name, ".log") &&
Expand Down
3 changes: 2 additions & 1 deletion src/rime/lever/switcher_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) {
}
for (fs::directory_iterator it(dir), end; it != end; ++it) {
path file_path(it->path());
if (boost::ends_with(file_path.string(), ".schema.yaml")) {
if (boost::ends_with(file_path.u8string(), ".schema.yaml")) {
Config config;
if (config.LoadFromFile(file_path)) {
SchemaInfo info;
Expand Down Expand Up @@ -86,6 +86,7 @@ void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) {
}
}
config.GetString("schema/description", &info.description);
// output path in native encoding.
info.file_path = file_path.string();
available_.push_back(info);
}
Expand Down

0 comments on commit 4d8bb87

Please sign in to comment.