refactor: filestem to cid into free fn
@@ -364,10 +364,26 @@ impl BlockStore for FsBlockStore {
ready(if path.extension() != Some("data".as_ref()) {
Ok(None)
} else {
- let maybe_cid =
- path.file_stem()
- .and_then(|stem| stem.to_str())
- .and_then(|s| {
+ let maybe_cid = filestem_to_cid(path.file_stem());
+ Ok(maybe_cid)
+ })
+ })
+ .try_collect::<Vec<_>>()
+ .await?;
+
+ Ok(vec)
+ }
+ .instrument(span)
+ .await
+ }
+
+ async fn wipe(&self) {
+ unimplemented!("wipe")
+ }
+}
+
+fn filestem_to_cid(file_stem: Option<&std::ffi::OsStr>) -> Option<Cid> {
+ file_stem.and_then(|stem| stem.to_str()).and_then(|s| {
let cid = Cid::try_from(s);
// it's very unlikely that we'd hit a valid file with "data" extension
@@ -383,23 +399,7 @@ impl BlockStore for FsBlockStore {
// FIXME: add test
cid.ok()
- });
-
- Ok(maybe_cid)
- })
})
- .try_collect::<Vec<_>>()
- .await?;
-
- Ok(vec)
- }
- .instrument(span)
- .await
- }
-
- async fn wipe(&self) {
- unimplemented!("wipe")
- }
}
fn block_path(mut base: PathBuf, cid: &Cid) -> PathBuf {
