Skip to content

Commit f8e4ebf

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

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/rime/lever/deployment_tasks.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,16 @@ bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) {
477477
fs::path entry(test->path());
478478
if (fs::is_symlink(entry)) {
479479
try {
480-
auto target_path = fs::canonical(entry);
481-
if (target_path.has_parent_path() &&
482-
fs::equivalent(shared_data_path, target_path.parent_path())) {
480+
// 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) {
483490
LOG(INFO) << "removing symlink: " << entry.filename().string();
484491
fs::remove(entry);
485492
}

0 commit comments

Comments
 (0)