From ea6fd0df6c38673659e6a8657299f2421f631569 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 20 Aug 2024 11:01:04 +0300 Subject: [PATCH] rust: Adjust EKO::close --- crates/dekoder/src/lib.rs | 9 +++++++-- crates/dekoder/tests/test_load.rs | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/dekoder/src/lib.rs b/crates/dekoder/src/lib.rs index 6d986de63..6ec7c1609 100644 --- a/crates/dekoder/src/lib.rs +++ b/crates/dekoder/src/lib.rs @@ -139,8 +139,13 @@ impl EKO { } /// Write content back to an archive and destroy working directory. - pub fn close(&self, allow_overwrite: bool) -> Result<()> { - self.write(allow_overwrite, true) + pub fn close(&self) -> Result<()> { + self.write(false, true) + } + + /// Write content back to an archive and destroy working directory. + pub fn overwrite_and_close(&self) -> Result<()> { + self.write(true, true) } /// Write content back to an archive. diff --git a/crates/dekoder/tests/test_load.rs b/crates/dekoder/tests/test_load.rs index 560ef9ca9..0998e3a35 100644 --- a/crates/dekoder/tests/test_load.rs +++ b/crates/dekoder/tests/test_load.rs @@ -12,6 +12,16 @@ fn v015tar() -> PathBuf { src } +#[test] +fn open() { + let src = v015tar(); + let dst = assert_fs::TempDir::new().unwrap(); + // open + let _ = EKO::edit(src.to_owned(), dst.to_owned()).unwrap(); + let metadata = dst.child("metadata.yaml"); + metadata.assert(predicate::path::exists()); +} + #[test] fn save_as_other() { let src = v015tar(); @@ -21,7 +31,7 @@ fn save_as_other() { // write to somewhere else let tarb = assert_fs::NamedTempFile::new("v0.15b.tar").unwrap(); eko.set_tar_path(tarb.to_owned()); - eko.close(true).unwrap(); + eko.overwrite_and_close().unwrap(); tarb.assert(predicate::path::exists()); } @@ -41,7 +51,7 @@ fn has_operator() { // it is the one assert!(ep.equals(eko.available_operators()[0], 64)); assert!(eko.has_operator(&ep, 64)); - eko.close(false).unwrap(); + eko.close().unwrap(); } #[test] @@ -58,5 +68,5 @@ fn load_operator() { let mut op = Operator::zeros(); eko.load_operator(&ep, 64, &mut op).unwrap(); assert!(op.op.dim().0 > 0); - eko.close(false).unwrap(); + eko.close().unwrap(); }