summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-11 16:07:36 +0100
committerGitHub <noreply@github.com>2018-02-11 16:07:36 +0100
commit938601f4fd6966b77333ef382eee8ae87d88cf28 (patch)
treeb448a92bbce8db63642f761517c1ff65e3e93869
parent2e4c29dd077cdaca4e7781397f855daf33780f78 (diff)
parent5e43773158197be3bf0d9c7fe414280372c1673f (diff)
downloadimag-938601f4fd6966b77333ef382eee8ae87d88cf28.zip
imag-938601f4fd6966b77333ef382eee8ae87d88cf28.tar.gz
Merge pull request #1267 from matthiasbeyer/imag-link/do-not-link-entry-with-itself
Do not allow linking with entry itself
-rw-r--r--bin/core/imag-link/src/main.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs
index 40155f9..8a004ee 100644
--- a/bin/core/imag-link/src/main.rs
+++ b/bin/core/imag-link/src/main.rs
@@ -61,6 +61,7 @@ use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagstore::error::StoreError;
use libimagstore::store::FileLockEntry;
+use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
use libimagutil::warn_result::*;
@@ -134,7 +135,16 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
.map_err_trace_exit_unwrap(1);
} else {
debug!("Linking internally: {:?} -> {:?}", from, entry);
- let mut to_entry = match get_entry_by_name(rt, entry) {
+
+ let from_id = StoreId::new_baseless(PathBuf::from(from)).map_err_trace_exit_unwrap(1);
+ let entr_id = StoreId::new_baseless(PathBuf::from(entry)).map_err_trace_exit_unwrap(1);
+
+ if from_id == entr_id {
+ error!("Cannot link entry with itself. Exiting");
+ ::std::process::exit(1)
+ }
+
+ let mut to_entry = match rt.store().get(entr_id) {
Ok(Some(e)) => e,
Ok(None) => {
warn!("No 'to' entry: {}", entry);