diff --git a/src/bin/download-speed.rs b/src/bin/download-speed.rs index dbb982b5..b3501c17 100644 --- a/src/bin/download-speed.rs +++ b/src/bin/download-speed.rs @@ -44,8 +44,8 @@ async fn run() -> Result<(), Error> { let mut bytes = 0; for _ in 0..100 { - let writer = DummyWriter { bytes: 0 }; - let writer = client.speedtest(writer).await?; + let mut writer = DummyWriter { bytes: 0 }; + client.speedtest(&mut writer).await?; println!("Received {} bytes", writer.bytes); bytes += writer.bytes; } diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index b05c60b5..55c8dac4 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -2199,7 +2199,7 @@ async fn catalog_shell(param: Value) -> Result<(), Error> { true, ).await?; - let tmpfile = std::fs::OpenOptions::new() + let mut tmpfile = std::fs::OpenOptions::new() .write(true) .read(true) .custom_flags(libc::O_TMPFILE) @@ -2216,7 +2216,7 @@ async fn catalog_shell(param: Value) -> Result<(), Error> { Arc::new(BufferedDynamicReadAt::new(reader)); let decoder = proxmox_backup::pxar::fuse::Accessor::new(reader, archive_size).await?; - let tmpfile = client.download(CATALOG_NAME, tmpfile).await?; + client.download(CATALOG_NAME, &mut tmpfile).await?; let index = DynamicIndexReader::new(tmpfile) .map_err(|err| format_err!("unable to read catalog index - {}", err))?; diff --git a/src/client/backup_reader.rs b/src/client/backup_reader.rs index d4f60ed0..9c9e14d1 100644 --- a/src/client/backup_reader.rs +++ b/src/client/backup_reader.rs @@ -91,7 +91,7 @@ impl BackupReader { &self, file_name: &str, output: W, - ) -> Result { + ) -> Result<(), Error> { let path = "download"; let param = json!({ "file-name": file_name }); self.h2.download(path, Some(param), output).await @@ -103,7 +103,7 @@ impl BackupReader { pub async fn speedtest( &self, output: W, - ) -> Result { + ) -> Result<(), Error> { self.h2.download("speedtest", None, output).await } @@ -112,7 +112,7 @@ impl BackupReader { &self, digest: &[u8; 32], output: W, - ) -> Result { + ) -> Result<(), Error> { let path = "chunk"; let param = json!({ "digest": digest_to_hex(digest) }); self.h2.download(path, Some(param), output).await @@ -127,7 +127,8 @@ impl BackupReader { use std::convert::TryFrom; - let raw_data = self.download(MANIFEST_BLOB_NAME, Vec::with_capacity(64*1024)).await?; + let mut raw_data = Vec::with_capacity(64 * 1024); + self.download(MANIFEST_BLOB_NAME, &mut raw_data).await?; let blob = DataBlob::from_raw(raw_data)?; blob.verify_crc()?; let data = blob.decode(self.crypt_config.as_ref().map(Arc::as_ref))?; @@ -146,13 +147,13 @@ impl BackupReader { name: &str, ) -> Result, Error> { - let tmpfile = std::fs::OpenOptions::new() + let mut tmpfile = std::fs::OpenOptions::new() .write(true) .read(true) .custom_flags(libc::O_TMPFILE) .open("/tmp")?; - let mut tmpfile = self.download(name, tmpfile).await?; + self.download(name, &mut tmpfile).await?; let (csum, size) = compute_file_csum(&mut tmpfile)?; manifest.verify_file(name, &csum, size)?; @@ -172,13 +173,13 @@ impl BackupReader { name: &str, ) -> Result { - let tmpfile = std::fs::OpenOptions::new() + let mut tmpfile = std::fs::OpenOptions::new() .write(true) .read(true) .custom_flags(libc::O_TMPFILE) .open("/tmp")?; - let tmpfile = self.download(name, tmpfile).await?; + self.download(name, &mut tmpfile).await?; let index = DynamicIndexReader::new(tmpfile) .map_err(|err| format_err!("unable to read dynamic index '{}' - {}", name, err))?; @@ -200,13 +201,13 @@ impl BackupReader { name: &str, ) -> Result { - let tmpfile = std::fs::OpenOptions::new() + let mut tmpfile = std::fs::OpenOptions::new() .write(true) .read(true) .custom_flags(libc::O_TMPFILE) .open("/tmp")?; - let tmpfile = self.download(name, tmpfile).await?; + self.download(name, &mut tmpfile).await?; let index = FixedIndexReader::new(tmpfile) .map_err(|err| format_err!("unable to read fixed index '{}' - {}", name, err))?; diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 52d699e1..3886c40f 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -466,7 +466,7 @@ impl HttpClient { &mut self, path: &str, output: &mut (dyn Write + Send), - ) -> Result<(), Error> { + ) -> Result<(), Error> { let mut req = Self::request_builder(&self.server, "GET", path, None).unwrap(); let client = self.client.clone(); @@ -707,7 +707,7 @@ impl H2Client { path: &str, param: Option, mut output: W, - ) -> Result { + ) -> Result<(), Error> { let request = Self::request_builder("localhost", "GET", path, param, None).unwrap(); let response_future = self.send_request(request, None).await?; @@ -727,7 +727,7 @@ impl H2Client { output.write_all(&chunk)?; } - Ok(output) + Ok(()) } pub async fn upload( diff --git a/src/client/pull.rs b/src/client/pull.rs index ea7099cf..5cf0dd1f 100644 --- a/src/client/pull.rs +++ b/src/client/pull.rs @@ -47,13 +47,13 @@ async fn download_manifest( filename: &std::path::Path, ) -> Result { - let tmp_manifest_file = std::fs::OpenOptions::new() + let mut tmp_manifest_file = std::fs::OpenOptions::new() .write(true) .create(true) .read(true) .open(&filename)?; - let mut tmp_manifest_file = reader.download(MANIFEST_BLOB_NAME, tmp_manifest_file).await?; + reader.download(MANIFEST_BLOB_NAME, &mut tmp_manifest_file).await?; tmp_manifest_file.seek(SeekFrom::Start(0))?; @@ -77,13 +77,13 @@ async fn pull_single_archive( tmp_path.set_extension("tmp"); worker.log(format!("sync archive {}", archive_name)); - let tmpfile = std::fs::OpenOptions::new() + let mut tmpfile = std::fs::OpenOptions::new() .write(true) .create(true) .read(true) .open(&tmp_path)?; - let tmpfile = reader.download(archive_name, tmpfile).await?; + reader.download(archive_name, &mut tmpfile).await?; match archive_type(archive_name)? { ArchiveType::DynamicIndex => { @@ -124,7 +124,7 @@ async fn try_client_log_download( .open(&tmp_path)?; // Note: be silent if there is no log - only log successful download - if let Ok(_) = reader.download(CLIENT_LOG_BLOB_NAME, tmpfile).await { + if let Ok(()) = reader.download(CLIENT_LOG_BLOB_NAME, tmpfile).await { if let Err(err) = std::fs::rename(&tmp_path, &path) { bail!("Atomic rename file {:?} failed - {}", path, err); }