aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/bootstrap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/bootstrap.rs')
-rw-r--r--src/swarm/bootstrap.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index 594db8f..b280b38 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -280,7 +280,7 @@ impl StoreStart {
/// The store `root` or `id` names, if either does: a root the federation takes as one,
/// with the events it keeps, which a store's root must be. The file `root` holds the
/// root on its first line, and, for a fork, the events it keeps, each on a line of its
- /// own: JCS, which writes no line break.
+ /// own (`federation::fork::root_file`).
pub(crate) fn of(root: Option<&Path>, id: Option<&str>, files: &Files) -> Result<Option<Self>> {
use crate::federation::fold::Federation;
use crate::federation::store::{Id, memory::Store};
@@ -293,12 +293,7 @@ impl StoreStart {
.read(FileKind::Store, path)
.with_context(|| format!("Reading the store's root {}", path.display()))?
.with_context(|| format!("The store's root {} doesn't exist", path.display()))?;
- let mut lines = file
- .split(|byte| *byte == b'\n')
- .filter(|line| !line.is_empty())
- .map(<[u8]>::to_vec);
- let root = lines.next().unwrap_or_default();
- let kept: Vec<Vec<u8>> = lines.collect();
+ let (root, kept) = crate::federation::fork::read_root_file(&file);
if let Err(refused) = Store::<Federation>::new(root.clone(), kept.clone()) {
bail!("The store's root {} is none: {}", path.display(), refused.0);
}
@@ -619,13 +614,7 @@ mod tests {
let dir = crate::files::scratch_dir("fork-root");
let (path, alone) = (dir.join("fork"), dir.join("alone"));
let files = Files::default();
- let mut file = root.clone();
- for event in &kept {
- file.push(b'\n');
- file.extend_from_slice(event);
- }
- file.push(b'\n');
- std::fs::write(&path, file).unwrap();
+ std::fs::write(&path, crate::federation::fork::root_file(&root, &kept)).unwrap();
std::fs::write(&alone, &root).unwrap();
let fork = StoreStart::of(Some(&path), None, &files).unwrap().unwrap();
assert_eq!(fork.id, Id::of(&root));