diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-09-05 16:10:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-05 16:10:47 +0200 |
commit | 737aab80dc029315d412ff781f20e9afd8db55ae (patch) | |
tree | 44d36cca30efa87b6964c185c46f75a7bd2fb043 /imag-store | |
parent | dfcc5c6a0e5bde7c5ed3ba40e3f6376b9e7d0a96 (diff) | |
parent | 07d4c45b3f21f07416f3d19bde122f11095467b4 (diff) |
Merge pull request #667 from matthiasbeyer/rewrite-storeid-type
Rewrite storeid type
Diffstat (limited to 'imag-store')
-rw-r--r-- | imag-store/src/create.rs | 29 | ||||
-rw-r--r-- | imag-store/src/delete.rs | 7 | ||||
-rw-r--r-- | imag-store/src/get.rs | 7 | ||||
-rw-r--r-- | imag-store/src/retrieve.rs | 7 | ||||
-rw-r--r-- | imag-store/src/update.rs | 6 | ||||
-rw-r--r-- | imag-store/tests/001-create_test.sh | 28 | ||||
-rw-r--r-- | imag-store/tests/002-retrieve_test.sh | 20 | ||||
-rw-r--r-- | imag-store/tests/003-delete_test.sh | 6 |
8 files changed, 66 insertions, 44 deletions
diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 7329df3f..0380ddf5 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -13,8 +13,9 @@ use clap::ArgMatches; use libimagrt::runtime::Runtime; use libimagstore::store::Entry; use libimagstore::store::EntryHeader; -use libimagstore::storeid::build_entry_path; +use libimagstore::storeid::StoreId; use libimagerror::trace::trace_error_exit; +use libimagutil::debug_result::*; use error::StoreError; use error::StoreErrorKind; @@ -36,13 +37,15 @@ pub fn create(rt: &Runtime) { exit(1); } - let path = match build_entry_path(rt.store(), path.unwrap()) { + let store_path = rt.store().path().clone(); + let path = match StoreId::new(Some(store_path), PathBuf::from(path.unwrap())) { Err(e) => trace_error_exit(&e, 1), - Ok(p) => p, + Ok(o) => o, }; debug!("path = {:?}", path); if scmd.subcommand_matches("entry").is_some() { + debug!("Creating entry from CLI specification"); create_from_cli_spec(rt, scmd, &path) .or_else(|_| create_from_source(rt, scmd, &path)) .or_else(|_| create_with_content_and_header(rt, @@ -50,13 +53,17 @@ pub fn create(rt: &Runtime) { String::new(), EntryHeader::new())) } else { + debug!("Creating entry"); create_with_content_and_header(rt, &path, String::new(), EntryHeader::new()) } - .unwrap_or_else(|e| debug!("Error building Entry: {:?}", e)) + .unwrap_or_else(|e| { + error!("Error building Entry"); + trace_error_exit(&e, 1); + }) }); } -fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> { +fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { let content = matches.subcommand_matches("entry") .map_or_else(|| { debug!("Didn't find entry subcommand, getting raw content"); @@ -80,7 +87,7 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> R create_with_content_and_header(rt, path, content, header) } -fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Result<()> { +fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { let content = matches .value_of("from-raw") .ok_or(StoreError::new(StoreErrorKind::NoCommandlineCall, None)) @@ -93,9 +100,11 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Res debug!("Content with len = {}", content.len()); Entry::from_str(path.clone(), &content[..]) + .map_dbg_err(|e| format!("Error building entry: {:?}", e)) .and_then(|new_e| { let r = rt.store() .create(path.clone()) + .map_dbg_err(|e| format!("Error in Store::create(): {:?}", e)) .map(|mut old_e| { *old_e.deref_mut() = new_e; }); @@ -103,17 +112,19 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Res debug!("Entry build"); r }) + .map_dbg_err(|e| format!("Error storing entry: {:?}", e)) .map_err(|serr| StoreError::new(StoreErrorKind::BackendError, Some(Box::new(serr)))) } fn create_with_content_and_header(rt: &Runtime, - path: &PathBuf, + path: &StoreId, content: String, header: EntryHeader) -> Result<()> { - debug!("Creating entry with content"); + debug!("Creating entry with content at {:?}", path); rt.store() - .create(PathBuf::from(path)) + .create(path.clone()) + .map_dbg_err(|e| format!("Error in Store::create(): {:?}", e)) .map(|mut element| { { let mut e_content = element.get_content_mut(); diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 46626816..537b638d 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -1,6 +1,8 @@ -use libimagstore::storeid::build_entry_path; +use std::path::PathBuf; + use libimagrt::runtime::Runtime; use libimagerror::trace::trace_error_exit; +use libimagstore::storeid::StoreId; pub fn delete(rt: &Runtime) { use std::process::exit; @@ -10,7 +12,8 @@ pub fn delete(rt: &Runtime) { .map(|sub| { sub.value_of("id") .map(|id| { - let path = try!(build_entry_path(rt.store(), id) + let path = PathBuf::from(id); + let path = try!(StoreId::new(Some(rt.store().path().clone()), path) .map_err(|e| trace_error_exit(&e, 1))); debug!("Deleting file at {:?}", id); diff --git a/imag-store/src/get.rs b/imag-store/src/get.rs index 3e33ac2b..1302b763 100644 --- a/imag-store/src/get.rs +++ b/imag-store/src/get.rs @@ -1,6 +1,8 @@ -use libimagstore::storeid::build_entry_path; +use std::path::PathBuf; + use libimagrt::runtime::Runtime; use libimagerror::trace::{trace_error, trace_error_exit}; +use libimagstore::storeid::StoreId; use retrieve::print_entry; @@ -10,7 +12,8 @@ pub fn get(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = match build_entry_path(rt.store(), id) { + let path = PathBuf::from(id); + let path = match StoreId::new(Some(rt.store().path().clone()), path) { Err(e) => trace_error_exit(&e, 1), Ok(p) => p, }; diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index f9f45993..39b66741 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -1,8 +1,10 @@ +use std::path::PathBuf; + use clap::ArgMatches; use toml::Value; use libimagstore::store::FileLockEntry; -use libimagstore::storeid::build_entry_path; +use libimagstore::storeid::StoreId; use libimagrt::runtime::Runtime; use libimagerror::trace::{trace_error, trace_error_exit}; @@ -12,7 +14,8 @@ pub fn retrieve(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = try!(build_entry_path(rt.store(), id) + let path = PathBuf::from(id); + let path = try!(StoreId::new(Some(rt.store().path().clone()), path) .map_err(|e| trace_error_exit(&e, 1))); debug!("path = {:?}", path); diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index 9959ec09..87279dc0 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -1,8 +1,9 @@ use std::ops::DerefMut; +use std::path::PathBuf; use libimagrt::runtime::Runtime; -use libimagstore::storeid::build_entry_path; use libimagerror::trace::trace_error_exit; +use libimagstore::storeid::StoreId; use util::build_toml_header; @@ -12,7 +13,8 @@ pub fn update(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = match build_entry_path(rt.store(), id) { + let path = PathBuf::from(id); + let path = match StoreId::new(Some(rt.store().path().clone()), path) { Err(e) => trace_error_exit(&e, 1), Ok(p) => p, }; diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh index 4f767c7d..3d030b34 100644 --- a/imag-store/tests/001-create_test.sh +++ b/imag-store/tests/001-create_test.sh @@ -4,7 +4,7 @@ source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh test_call() { - imag-store create -p /test-call~0.2.0 + imag-store create -p test-call if [[ ! $? -eq 0 ]]; then err "Return value should be zero, was non-zero" return 1; @@ -12,7 +12,7 @@ test_call() { } test_call_id() { - imag-store create -i /test-call~0.2.0 + imag-store create -i test-call if [[ ! $? -eq 0 ]]; then err "Return value should be zero, was non-zero" return 1; @@ -28,7 +28,7 @@ test_call_no_id() { } test_mkstore() { - imag-store create -p /test-mkstore~0.2.0 || { err "Calling imag failed"; return 1; } + imag-store create -p test-mkstore || { err "Calling imag failed"; return 1; } if [[ -d ${STORE} ]]; then out "Store exists." else @@ -48,12 +48,12 @@ version = "0.2.0" EOS ) - imag-store create -p /test-std-header~0.2.0 - local result=$(cat ${STORE}/test-std-header~0.2.0) + imag-store create -p test-std-header + local result=$(cat ${STORE}/test-std-header) if [[ "$expected" == "$result" ]]; then out "Expected store entry == result" else - err "${STORE}/test-std-header~0.2.0 differs from expected" + err "${STORE}/test-std-header differs from expected" return 1 fi } @@ -72,8 +72,8 @@ zzz = "z" EOS ) - imag-store create -p /test-std-header-plus-custom~0.2.0 entry -h zzz.zzz=z - local result=$(cat ${STORE}/test-std-header-plus-custom~0.2.0) + imag-store create -p test-std-header-plus-custom entry -h zzz.zzz=z + local result=$(cat ${STORE}/test-std-header-plus-custom) if [[ "$expected" == "$result" ]]; then out "Expected store entry == result" else @@ -99,8 +99,8 @@ zzz = "z" EOS ) - local filename="test-std-header-plus-custom-multiheader~0.2.0" - imag-store create -p /$filename entry -h zzz.zzz=z foo.bar=baz + local filename="test-std-header-plus-custom-multiheader" + imag-store create -p $filename entry -h zzz.zzz=z foo.bar=baz local result=$(cat ${STORE}/$filename) if [[ "$expected" == "$result" ]]; then out "Expected store entry == result" @@ -126,8 +126,8 @@ zzz = "z" EOS ) - local filename="test-std-header-plus-custom-mutliheader-same-section~0.2.0" - imag-store create -p /$filename entry -h zzz.zzz=z zzz.bar=baz + local filename="test-std-header-plus-custom-mutliheader-same-section" + imag-store create -p $filename entry -h zzz.zzz=z zzz.bar=baz local result=$(cat ${STORE}/$filename) if [[ "$expected" == "$result" ]]; then out "Expected store entry == result" @@ -151,8 +151,8 @@ content EOS ) - local name="test-std-header-plus-custom-and-content~0.2.0" - imag-store create -p /$name entry -h zzz.zzz=z -c content + local name="test-std-header-plus-custom-and-content" + imag-store create -p $name entry -h zzz.zzz=z -c content local result=$(cat ${STORE}/$name) if [[ "$expected" == "$result" ]]; then out "Expected store entry == result" diff --git a/imag-store/tests/002-retrieve_test.sh b/imag-store/tests/002-retrieve_test.sh index 01fcfd3e..1e6e7203 100644 --- a/imag-store/tests/002-retrieve_test.sh +++ b/imag-store/tests/002-retrieve_test.sh @@ -18,9 +18,9 @@ retrieve() { } test_retrieve_nothing() { - local id="test-retrieve_nothing~0.2.0" + local id="test-retrieve_nothing" - imag-store create -p /${id} || { err "create failed"; return 1; } + imag-store create -p ${id} || { err "create failed"; return 1; } out "Going to test the retrieve functionality now" local zero_out="$(retrieve --id /${id})" @@ -33,9 +33,9 @@ test_retrieve_nothing() { } test_retrieve_content() { - local id="test-retrieve_simple~0.2.0" + local id="test-retrieve_simple" - imag-store create -p /${id} || { err "create failed"; return 1; } + imag-store create -p ${id} || { err "create failed"; return 1; } out "Going to test the retrieve functionality now" @@ -49,12 +49,12 @@ test_retrieve_content() { } test_retrieve_header() { - local id="test-retrieve_simple~0.2.0" + local id="test-retrieve_simple" - imag-store create -p /${id} || { err "create failed"; return 1; } + imag-store create -p ${id} || { err "create failed"; return 1; } out "Going to test the retrieve functionality now" - local header_out="$(retrieve --id /${id} --header)" + local header_out="$(retrieve --id ${id} --header)" out "Retrieving for header_out finished" if [[ ! "$header_out" != "$(std_header)" ]]; then @@ -64,12 +64,12 @@ test_retrieve_header() { } test_retrieve_raw() { - local id="test-retrieve_simple~0.2.0" + local id="test-retrieve_simple" - imag-store create -p /${id} || { err "create failed"; return 1; } + imag-store create -p ${id} || { err "create failed"; return 1; } out "Going to test the retrieve functionality now" - local both_out="$(retrieve --id /${id} --raw)" + local both_out="$(retrieve --id ${id} --raw)" out "Retrieving for both_out finished" if [[ "$both_out" != "$(std_header)" ]]; then diff --git a/imag-store/tests/003-delete_test.sh b/imag-store/tests/003-delete_test.sh index a0eb97a2..a3d890e5 100644 --- a/imag-store/tests/003-delete_test.sh +++ b/imag-store/tests/003-delete_test.sh @@ -12,10 +12,10 @@ delete() { } test_delete_simple() { - local name="test~0.2.0" + local name="test" - create -p /$name - delete --id /$name + create -p $name + delete --id $name local n=$($(find ${STORE}/ -type f | wc -l)) if [[ $n -eq 0 ]]; then |