summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-02 23:10:06 +0100
committerGitHub <noreply@github.com>2018-03-02 23:10:06 +0100
commit7cd3bb059f9eb729650614d00cabf65f857c7af9 (patch)
tree41dbd8a2fe9230ba49f4f7256c1c655eb78d6a85
parentef3b60eea57356efd4871cc44f43aaad346ac196 (diff)
parent2089f96464fd98800bb3e34b0021d0abcb14a914 (diff)
downloadimag-7cd3bb059f9eb729650614d00cabf65f857c7af9.zip
imag-7cd3bb059f9eb729650614d00cabf65f857c7af9.tar.gz
Merge pull request #1319 from matthiasbeyer/libimagstore/fix-read-into-single-line-bug
libimagstore: fix read into single line bug
-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 abfc9f4..76b2f83 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -60,6 +60,8 @@ This section contains the changelog from the last release to the next release.
when tracing.
* A parsing error in `libimagstore`, which caused the parsing of entries
with a line "---" in the content part to fail, was fixed.
+ * The patch explained by the point above introduced a bug which caused
+ entries to be read as a single line, which was fixed as well.
## 0.6.1
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index 30da5c9..1b0cc49 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)?;
+ }
}
}
}