Skip to content

Commit afa0e47

Browse files
committed
fix: move FsBlockStore::list outside of async_trait
see comments in rs-ipfs#458. it is unknown why this is needed but it does work away of the compiler error.
1 parent d6838f1 commit afa0e47

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

src/repo/fs/blocks.rs

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,49 @@ impl FsBlockStore {
100100
}
101101
}
102102
}
103+
104+
async fn list0(&self) -> Result<Vec<Cid>, Error> {
105+
use futures::future::{ready, Either};
106+
use futures::stream::{empty, TryStreamExt};
107+
use tokio_stream::wrappers::ReadDirStream;
108+
109+
let span = tracing::trace_span!("listing blocks");
110+
111+
async move {
112+
let stream = ReadDirStream::new(fs::read_dir(self.path.clone()).await?);
113+
114+
// FIXME: written as a stream to make the Vec be BoxStream<'static, Cid>
115+
let vec = stream
116+
.and_then(|d| async move {
117+
// map over the shard directories
118+
Ok(if d.file_type().await?.is_dir() {
119+
Either::Left(ReadDirStream::new(fs::read_dir(d.path()).await?))
120+
} else {
121+
Either::Right(empty())
122+
})
123+
})
124+
// flatten each
125+
.try_flatten()
126+
// convert the paths ending in ".data" into cid
127+
.try_filter_map(|d| {
128+
let name = d.file_name();
129+
let path: &std::path::Path = name.as_ref();
130+
131+
ready(if path.extension() != Some("data".as_ref()) {
132+
Ok(None)
133+
} else {
134+
let maybe_cid = filestem_to_block_cid(path.file_stem());
135+
Ok(maybe_cid)
136+
})
137+
})
138+
.try_collect::<Vec<_>>()
139+
.await?;
140+
141+
Ok(vec)
142+
}
143+
.instrument(span)
144+
.await
145+
}
103146
}
104147

105148
#[async_trait]
@@ -355,46 +398,7 @@ impl BlockStore for FsBlockStore {
355398
}
356399

357400
async fn list(&self) -> Result<Vec<Cid>, Error> {
358-
use futures::future::{ready, Either};
359-
use futures::stream::{empty, TryStreamExt};
360-
use tokio_stream::wrappers::ReadDirStream;
361-
362-
let span = tracing::trace_span!("listing blocks");
363-
364-
async move {
365-
let stream = ReadDirStream::new(fs::read_dir(self.path.clone()).await?);
366-
367-
// FIXME: written as a stream to make the Vec be BoxStream<'static, Cid>
368-
let vec = stream
369-
.and_then(|d| async move {
370-
// map over the shard directories
371-
Ok(if d.file_type().await?.is_dir() {
372-
Either::Left(ReadDirStream::new(fs::read_dir(d.path()).await?))
373-
} else {
374-
Either::Right(empty())
375-
})
376-
})
377-
// flatten each
378-
.try_flatten()
379-
// convert the paths ending in ".data" into cid
380-
.try_filter_map(|d| {
381-
let name = d.file_name();
382-
let path: &std::path::Path = name.as_ref();
383-
384-
ready(if path.extension() != Some("data".as_ref()) {
385-
Ok(None)
386-
} else {
387-
let maybe_cid = filestem_to_block_cid(path.file_stem());
388-
Ok(maybe_cid)
389-
})
390-
})
391-
.try_collect::<Vec<_>>()
392-
.await?;
393-
394-
Ok(vec)
395-
}
396-
.instrument(span)
397-
.await
401+
self.list0().await
398402
}
399403

400404
async fn wipe(&self) {

0 commit comments

Comments
 (0)