Skip to content

Commit

Permalink
fix sftp read
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Sep 28, 2024
1 parent f1d92b1 commit f65cdfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions core/src/services/sftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ impl Access for SftpBackend {
.await
.map_err(parse_sftp_error)?;

let meta = f.metadata().await.map_err(parse_sftp_error)?;

if args.range().offset() != 0 {
f.seek(SeekFrom::Start(args.range().offset()))
.await
Expand All @@ -406,7 +404,7 @@ impl Access for SftpBackend {

Ok((
RpRead::default(),
SftpReader::new(client, f, args.range().size().and(meta.len())),
SftpReader::new(client, f, args.range().size()),
))
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/services/sftp/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl SftpReader {

impl oio::Read for SftpReader {
async fn read(&mut self) -> Result<Buffer> {
if Some(self.read) >= self.size {
if self.read >= self.size.unwrap_or(usize::MAX) {
return Ok(Buffer::new());
}

Expand All @@ -71,6 +71,8 @@ impl oio::Read for SftpReader {
};

self.read += bytes.len();
Ok(Buffer::from(bytes.freeze()))
self.buf = bytes;
let bs = self.buf.split();
Ok(Buffer::from(bs.freeze()))
}
}

0 comments on commit f65cdfc

Please sign in to comment.