summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-02 23:12:47 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-03-02 23:13:56 +0100
commitb8ac97cdfbb6021769fb074560adbfffc01aefa0 (patch)
tree68e831fb2d99bc40dc53aedb61a2d1f00e90732d
parent8b866c51bf19a4ed4818d847a5ec3a4b90bb7eb8 (diff)
Fix multi-line reading
Reading entries with multiple entries caused all lines to be read as one line. This bug is fixed with this patch and a testcase was added. --- This patch was cherry-picked from 87d6f1221fa0e3a6d5f6095ede6006d3003bdff9 and ee5a17790f3e4ccf9d387ca7626ca654f564cb65 plus a changelog entry was added.
-rw-r--r--doc/src/09020-changelog.md2
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs21
-rw-r--r--lib/core/libimagstore/src/util.rs10
3 files changed, 31 insertions, 2 deletions
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 04bad33..e677fd1 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -29,6 +29,8 @@ Bugfix release for fixing:
* `imag-diary` did not recognize the "-d DIARY" setting.
* A parsing error in `libimagstore`, which caused the parsing of entries
with a line "---" in the content part to fail, was fixed.
+* The bugfix above introduced another bug which caused entries to be rewritten
+ in one line when accessing them. This was fixed.
## 0.6.1
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index 3e80fcb..a5f84fa 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -123,5 +123,26 @@ Hello World"#).unwrap();
assert_eq!(bah.get_content(), "Hello World");
}
+ #[test]
+ fn lazy_file_multiline() {
+ let fs = InMemoryFileAbstraction::new();
+
+ let mut path = PathBuf::from("tests");
+ path.set_file_name("test1");
+ let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
+
+ let loca = StoreId::new_baseless(path).unwrap();
+ let file = Entry::from_str(loca.clone(), r#"---
+[imag]
+version = "0.7.0"
+---
+Hello World
+baz"#).unwrap();
+
+ lf.write_file_content(&file).unwrap();
+ let bah = lf.get_file_content(loca).unwrap();
+ assert_eq!(bah.get_content(), "Hello World\nbaz");
+ }
+
}
diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs
index 160ecf6..55222f7 100644
--- a/lib/core/libimagstore/src/util.rs
+++ b/lib/core/libimagstore/src/util.rs
@@ -46,7 +46,9 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
let mut content = String::new();
let mut header_consumed = false;
- for line in buf.lines().skip(1) { // the first line is "---"
+ let mut iter = buf.lines().skip(1).peekable(); // the first line is "---"
+
+ while let Some(line) = iter.next() {
if line == "---" {
header_consumed = true;
// do not further process the line
@@ -54,7 +56,11 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
if !header_consumed {
let _ = writeln!(header, "{}", line)?;
} else {
- let _ = write!(content, "{}", line)?;
+ if iter.peek().is_some() {
+ let _ = writeln!(content, "{}", line)?;
+ } else {
+ let _ = write!(content, "{}", line)?;
+ }
}
}
}