Skip to content

Commit 5ad333d

Browse files
committed
fix(SymlinkingPrebuiltDictionaries): remove dangling symlinks
Closes #241
1 parent f8e4ebf commit 5ad333d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/rime/lever/deployment_tasks.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -478,21 +478,20 @@ bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) {
478478
if (fs::is_symlink(entry)) {
479479
try {
480480
// a symlink becomes dangling if the target file is no longer provided
481-
bool symlink_valid = fs::status_known(fs::symlink_status(entry));
482-
bool linked_to_shared_data = false;
483-
if (symlink_valid) {
484-
auto target_path = fs::canonical(entry);
485-
linked_to_shared_data =
486-
target_path.has_parent_path() &&
487-
fs::equivalent(shared_data_path, target_path.parent_path());
488-
}
489-
if (!symlink_valid || linked_to_shared_data) {
481+
boost::system::error_code ec;
482+
auto target_path = fs::canonical(entry, ec);
483+
bool bad_link = bool(ec);
484+
bool linked_to_shared_data =
485+
!bad_link &&
486+
target_path.has_parent_path() &&
487+
fs::equivalent(shared_data_path, target_path.parent_path());
488+
if (bad_link || linked_to_shared_data) {
490489
LOG(INFO) << "removing symlink: " << entry.filename().string();
491490
fs::remove(entry);
492491
}
493492
}
494493
catch (const fs::filesystem_error& ex) {
495-
LOG(ERROR) << ex.what();
494+
LOG(ERROR) << entry << ": " << ex.what();
496495
success = false;
497496
}
498497
}

0 commit comments

Comments
 (0)