Skip to content

Commit

Permalink
fix(SymlinkingPrebuiltDictionaries): remove dangling symlinks
Browse files Browse the repository at this point in the history
Closes #241
  • Loading branch information
lotem committed Jan 4, 2019
1 parent 68c8a34 commit f8e4ebf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,16 @@ bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) {
fs::path entry(test->path());
if (fs::is_symlink(entry)) {
try {
auto target_path = fs::canonical(entry);
if (target_path.has_parent_path() &&
fs::equivalent(shared_data_path, target_path.parent_path())) {
// a symlink becomes dangling if the target file is no longer provided
bool symlink_valid = fs::status_known(fs::symlink_status(entry));
bool linked_to_shared_data = false;
if (symlink_valid) {
auto target_path = fs::canonical(entry);
linked_to_shared_data =
target_path.has_parent_path() &&
fs::equivalent(shared_data_path, target_path.parent_path());
}
if (!symlink_valid || linked_to_shared_data) {
LOG(INFO) << "removing symlink: " << entry.filename().string();
fs::remove(entry);
}
Expand Down

0 comments on commit f8e4ebf

Please sign in to comment.