Skip to content

Commit 7fb070d

Browse files
authored
error out when dump is not a file (#1526)
1 parent 355ec0a commit 7fb070d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

libsql-server/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ pub enum LoadDumpError {
286286
NoTxn,
287287
#[error("The dump should commit the transaction.")]
288288
NoCommit,
289+
#[error("Path is not a file")]
290+
NotAFile,
289291
}
290292

291293
impl ResponseError for LoadDumpError {}
@@ -303,6 +305,7 @@ impl IntoResponse for &LoadDumpError {
303305
| UnsupportedUrlScheme(_)
304306
| NoTxn
305307
| NoCommit
308+
| NotAFile
306309
| DumpFilePathNotAbsolute => self.format_err(StatusCode::BAD_REQUEST),
307310
}
308311
}

libsql-server/src/http/admin/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ where
408408
return Err(LoadDumpError::DumpFileDoesntExist);
409409
}
410410

411+
if !path.is_file() {
412+
return Err(LoadDumpError::NotAFile);
413+
}
414+
411415
let f = tokio::fs::File::open(path).await?;
412416

413417
Ok(Box::new(ReaderStream::new(f)))

libsql-wal/src/bottomless/storage/fs.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<I: Io> Storage for FsStorage<I> {
4545

4646
let path = self.prefix.join("segments").join(key);
4747

48-
let buf = Vec::with_capacity(dbg!(segment_data.len().unwrap()) as usize);
48+
let buf = Vec::with_capacity(segment_data.len().unwrap() as usize);
4949

50-
let f = self.io.open(true, false, true, dbg!(&path)).unwrap();
50+
let f = self.io.open(true, false, true, &path).unwrap();
5151
async move {
5252
let (buf, res) = segment_data.read_exact_at_async(buf, 0).await;
5353

@@ -88,10 +88,7 @@ impl<I: Io> Storage for FsStorage<I> {
8888
use crate::io::buf::ZeroCopyBuf;
8989

9090
let header_buf = ZeroCopyBuf::<CompactedSegmentDataHeader>::new_uninit();
91-
let file = self
92-
.io
93-
.open(false, true, false, dbg!(&entry.path()))
94-
.unwrap();
91+
let file = self.io.open(false, true, false, &entry.path()).unwrap();
9592
let (header_buf, res) = file.read_exact_at_async(header_buf, 0).await;
9693
res.unwrap();
9794

0 commit comments

Comments
 (0)