Skip to content

Commit dff836e

Browse files
committed
fix some panics
1 parent 26b79ec commit dff836e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/store/fs.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ where
17791779
tokio::select! {
17801780
msg = msgs.recv() => {
17811781
if let Some(msg) = msg {
1782-
if let Err(msg) = self.state.handle_readonly(&tables, msg)? {
1782+
if let Err(msg) = self.state.handle_readonly(&tables, msg).await? {
17831783
msgs.push_back(msg).expect("just recv'd");
17841784
break;
17851785
}
@@ -1808,7 +1808,7 @@ where
18081808
tokio::select! {
18091809
msg = msgs.recv() => {
18101810
if let Some(msg) = msg {
1811-
if let Err(msg) = self.state.handle_readwrite(&mut tables, msg)? {
1811+
if let Err(msg) = self.state.handle_readwrite(&mut tables, msg).await? {
18121812
msgs.push_back(msg).expect("just recv'd");
18131813
break;
18141814
}
@@ -1853,7 +1853,7 @@ where
18531853
Ok(status)
18541854
}
18551855

1856-
fn get(
1856+
async fn get(
18571857
&mut self,
18581858
tables: &impl ReadableTables,
18591859
hash: Hash,
@@ -1873,15 +1873,17 @@ where
18731873
data_location,
18741874
outboard_location,
18751875
} => {
1876-
let data = load_data(tables, &self.options.path, data_location, &hash, &*self.fs)?;
1876+
let data =
1877+
load_data(tables, &self.options.path, data_location, &hash, &*self.fs).await?;
18771878
let outboard = load_outboard(
18781879
tables,
18791880
&self.options.path,
18801881
outboard_location,
18811882
data.size(),
18821883
&hash,
18831884
&*self.fs,
1884-
)?;
1885+
)
1886+
.await?;
18851887
BaoFileHandle::new_complete(config, hash, data, outboard)
18861888
}
18871889
EntryState::Partial { .. } => BaoFileHandle::incomplete_file(config, hash)?,
@@ -2102,7 +2104,7 @@ where
21022104
Ok((tag, data_size))
21032105
}
21042106

2105-
fn get_or_create(
2107+
async fn get_or_create(
21062108
&mut self,
21072109
tables: &impl ReadableTables,
21082110
hash: Hash,
@@ -2121,15 +2123,17 @@ where
21212123
..
21222124
} => {
21232125
let data =
2124-
load_data(tables, &self.options.path, data_location, &hash, &*self.fs)?;
2126+
load_data(tables, &self.options.path, data_location, &hash, &*self.fs)
2127+
.await?;
21252128
let outboard = load_outboard(
21262129
tables,
21272130
&self.options.path,
21282131
outboard_location,
21292132
data.size(),
21302133
&hash,
21312134
&*self.fs,
2132-
)?;
2135+
)
2136+
.await?;
21332137
tracing::debug!("creating complete entry for {}", hash.to_hex());
21342138
BaoFileHandle::new_complete(self.create_options.clone(), hash, data, outboard)
21352139
}
@@ -2530,18 +2534,18 @@ where
25302534
Ok(())
25312535
}
25322536

2533-
fn handle_readonly(
2537+
async fn handle_readonly(
25342538
&mut self,
25352539
tables: &impl ReadableTables,
25362540
msg: ActorMessage<T::File>,
25372541
) -> ActorResult<std::result::Result<(), ActorMessage<T::File>>> {
25382542
match msg {
25392543
ActorMessage::Get { hash, tx } => {
2540-
let res = self.get(tables, hash);
2544+
let res = self.get(tables, hash).await;
25412545
tx.send(res).ok();
25422546
}
25432547
ActorMessage::GetOrCreate { hash, tx } => {
2544-
let res = self.get_or_create(tables, hash);
2548+
let res = self.get_or_create(tables, hash).await;
25452549
tx.send(res).ok();
25462550
}
25472551
ActorMessage::EntryStatus { hash, tx } => {
@@ -2577,9 +2581,9 @@ where
25772581
Ok(Ok(()))
25782582
}
25792583

2580-
fn handle_readwrite(
2584+
async fn handle_readwrite(
25812585
&mut self,
2582-
tables: &mut Tables,
2586+
tables: &mut Tables<'_>,
25832587
msg: ActorMessage<T::File>,
25842588
) -> ActorResult<std::result::Result<(), ActorMessage<T::File>>> {
25852589
match msg {
@@ -2632,7 +2636,7 @@ where
26322636
}
26332637
msg => {
26342638
// try to handle it as readonly
2635-
if let Err(msg) = self.handle_readonly(tables, msg)? {
2639+
if let Err(msg) = self.handle_readonly(tables, msg).await? {
26362640
return Ok(Err(msg));
26372641
}
26382642
}
@@ -2700,7 +2704,7 @@ where
27002704
rx.blocking_recv().expect("The sender cannot be dropped")
27012705
}
27022706

2703-
fn load_data<T>(
2707+
async fn load_data<T>(
27042708
tables: &impl ReadableTables,
27052709
options: &PathOptions,
27062710
location: DataLocation<(), u64>,
@@ -2722,7 +2726,7 @@ where
27222726
}
27232727
DataLocation::Owned(data_size) => {
27242728
let path = options.owned_data_path(hash);
2725-
let Ok(file) = block_for(fs.open(&path)) else {
2729+
let Ok(file) = fs.open(&path).await else {
27262730
return Err(io::Error::new(
27272731
io::ErrorKind::NotFound,
27282732
format!("file not found: {}", path.display()),
@@ -2741,7 +2745,7 @@ where
27412745
));
27422746
}
27432747
let path = &paths[0];
2744-
let Ok(file) = block_for(fs.open(path)) else {
2748+
let Ok(file) = fs.open(path).await else {
27452749
return Err(io::Error::new(
27462750
io::ErrorKind::NotFound,
27472751
format!("external file not found: {}", path.display()),
@@ -2756,7 +2760,7 @@ where
27562760
})
27572761
}
27582762

2759-
fn load_outboard<T: Persistence>(
2763+
async fn load_outboard<T: Persistence>(
27602764
tables: &impl ReadableTables,
27612765
options: &PathOptions,
27622766
location: OutboardLocation,
@@ -2778,7 +2782,7 @@ fn load_outboard<T: Persistence>(
27782782
OutboardLocation::Owned => {
27792783
let outboard_size = raw_outboard_size(size);
27802784
let path = options.owned_outboard_path(hash);
2781-
let Ok(file) = block_for(fs.open(&path)) else {
2785+
let Ok(file) = fs.open(&path).await else {
27822786
return Err(io::Error::new(
27832787
io::ErrorKind::NotFound,
27842788
format!("file not found: {} size={}", path.display(), outboard_size),

0 commit comments

Comments
 (0)