node: Add `Storage::open`
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
2c519f5b5f
commit
a5a7af57b5
|
|
@ -1,5 +1,5 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::{fmt, fs};
|
||||
use std::{fmt, fs, io};
|
||||
|
||||
use git_ref_format::refspec;
|
||||
use git_url::Url;
|
||||
|
|
@ -59,10 +59,16 @@ impl WriteStorage for Storage {
|
|||
}
|
||||
|
||||
impl Storage {
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> Self {
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, io::Error> {
|
||||
let path = path.as_ref().to_path_buf();
|
||||
|
||||
Self { path }
|
||||
match fs::create_dir_all(&path) {
|
||||
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
|
||||
Err(err) => return Err(err),
|
||||
Ok(()) => {}
|
||||
}
|
||||
|
||||
Ok(Self { path })
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
|
|
@ -231,7 +237,7 @@ mod tests {
|
|||
fn test_fetch() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let alice = fixtures::storage(tmp.path().join("alice"));
|
||||
let bob = Storage::new(tmp.path().join("bob"));
|
||||
let bob = Storage::open(tmp.path().join("bob")).unwrap();
|
||||
let inventory = alice.inventory().unwrap();
|
||||
let proj = inventory.first().unwrap();
|
||||
let remotes = alice.repository(proj).unwrap().remotes().unwrap();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::test::arbitrary;
|
|||
|
||||
pub fn storage<P: AsRef<Path>>(path: P) -> Storage {
|
||||
let path = path.as_ref();
|
||||
let storage = Storage::new(path);
|
||||
let storage = Storage::open(path).unwrap();
|
||||
let proj_ids = arbitrary::set::<ProjId>(3..5);
|
||||
let user_ids = arbitrary::set::<UserId>(1..3);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ use nakamoto_net::Protocol as _;
|
|||
|
||||
use crate::collections::{HashMap, HashSet};
|
||||
use crate::protocol::*;
|
||||
use crate::storage::git::Storage;
|
||||
use crate::storage::ReadStorage;
|
||||
use crate::test::fixtures;
|
||||
#[allow(unused)]
|
||||
use crate::test::logger;
|
||||
use crate::test::peer::Peer;
|
||||
|
|
|
|||
Loading…
Reference in New Issue