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 5, 2019
1 parent f8e4ebf commit 5ad333d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,21 +478,20 @@ bool SymlinkingPrebuiltDictionaries::Run(Deployer* deployer) {
if (fs::is_symlink(entry)) {
try {
// 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) {
boost::system::error_code ec;
auto target_path = fs::canonical(entry, ec);
bool bad_link = bool(ec);
bool linked_to_shared_data =
!bad_link &&
target_path.has_parent_path() &&
fs::equivalent(shared_data_path, target_path.parent_path());
if (bad_link || linked_to_shared_data) {
LOG(INFO) << "removing symlink: " << entry.filename().string();
fs::remove(entry);
}
}
catch (const fs::filesystem_error& ex) {
LOG(ERROR) << ex.what();
LOG(ERROR) << entry << ": " << ex.what();
success = false;
}
}
Expand Down

0 comments on commit 5ad333d

Please sign in to comment.