Skip to content

Commit

Permalink
return u64 from open_file, create_file
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jan 4, 2022
1 parent 9420b3a commit 03e0a6f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ impl RemoteFs for AwsS3Fs {
fn create_file(
&mut self,
path: &Path,
_metadata: &Metadata,
metadata: &Metadata,
mut reader: Box<dyn Read>,
) -> RemoteResult<()> {
) -> RemoteResult<u64> {
self.check_connection()?;
let src = self.resolve(path);
let key = Self::fmt_path(src.as_path(), false);
Expand All @@ -470,20 +470,20 @@ impl RemoteFs for AwsS3Fs {
.as_ref()
.unwrap()
.put_object_stream(&mut reader, key.as_str())
.map(|_| ())
.map_err(|e| {
RemoteError::new_ex(
RemoteErrorType::ProtocolError,
format!("Could not put file: {}", e),
)
})
.map(|_| metadata.size)
}

fn open_file(
&mut self,
src: &Path,
mut dest: Box<dyn std::io::Write + Send>,
) -> RemoteResult<()> {
) -> RemoteResult<u64> {
self.check_connection()?;
if !self.exists(src).ok().unwrap_or(false) {
return Err(RemoteError::new(RemoteErrorType::NoSuchFileOrDirectory));
Expand All @@ -495,13 +495,13 @@ impl RemoteFs for AwsS3Fs {
.as_ref()
.unwrap()
.get_object_stream(key.as_str(), &mut dest)
.map(|_| ())
.map_err(|e| {
RemoteError::new_ex(
RemoteErrorType::ProtocolError,
format!("Could not get file: {}", e),
)
})
.map(|_| 0)
}
}

Expand Down Expand Up @@ -733,7 +733,13 @@ mod test {
let reader = Cursor::new(file_data.as_bytes());
let mut metadata = Metadata::default();
metadata.size = file_data.len() as u64;
assert!(client.create_file(p, &metadata, Box::new(reader)).is_ok());
assert_eq!(
client
.create_file(p, &metadata, Box::new(reader))
.ok()
.unwrap(),
10
);
// Verify size
assert_eq!(client.stat(p).ok().unwrap().metadata().size, 10);
finalize_client(client);
Expand Down Expand Up @@ -837,7 +843,7 @@ mod test {
assert!(client.create_file(p, &metadata, Box::new(reader)).is_ok());
// Verify size
let buffer: Box<dyn std::io::Write + Send> = Box::new(Vec::with_capacity(512));
assert!(client.open_file(p, buffer).is_ok());
assert_eq!(client.open_file(p, buffer).ok().unwrap(), 0);
finalize_client(client);
}

Expand Down

0 comments on commit 03e0a6f

Please sign in to comment.