Skip to content

Commit bfc9a84

Browse files
committed
utils: drop unused reader tracking
1 parent 24d6b7e commit bfc9a84

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

src/dist/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22
use std::fs;
3+
use std::io::Read;
34
use std::ops;
45
use std::path::{Path, PathBuf};
56
use std::sync::Mutex;
@@ -410,8 +411,7 @@ impl DownloadStatus {
410411

411412
fn file_hash(path: &Path) -> Result<String> {
412413
let mut hasher = Sha256::new();
413-
let mut downloaded = utils::FileReaderWithProgress::new_file(path)?;
414-
use std::io::Read;
414+
let mut downloaded = utils::buffered(path)?;
415415
let mut buf = vec![0; 32768];
416416
while let Ok(n) = downloaded.read(&mut buf) {
417417
if n == 0 {

src/dist/manifestation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl Manifestation {
399399
}
400400

401401
// Install all the components in the installer
402-
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
402+
let reader = utils::buffered(&installer_file)?;
403403
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
404404
let io_executor = get_executor(
405405
unpack_ram(IO_CHUNK_SIZE, dl_cfg.process.unpack_ram()?),
@@ -687,7 +687,7 @@ impl<'a> ComponentBinary<'a> {
687687

688688
self.status.installing();
689689

690-
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
690+
let reader = utils::buffered(&installer_file)?;
691691
let temp_dir = self.download_cfg.tmp_cx.new_directory()?;
692692
let io_executor = get_executor(
693693
unpack_ram(IO_CHUNK_SIZE, self.download_cfg.process.unpack_ram()?),

src/utils/mod.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::{BitAnd, BitAndAssign};
88
use std::path::{Path, PathBuf};
99
use std::process::ExitStatus;
1010

11-
use anyhow::{Context, Result, anyhow, bail};
11+
use anyhow::{Context, Result, anyhow};
1212
use retry::delay::{Fibonacci, jitter};
1313
use retry::{OperationResult, retry};
1414
use tracing::{debug, info, warn};
@@ -441,40 +441,13 @@ pub(crate) fn delete_dir_contents_following_links(dir_path: &Path) {
441441
}
442442
}
443443

444-
pub(crate) struct FileReaderWithProgress {
445-
fh: BufReader<File>,
446-
nbytes: u64,
447-
}
448-
449-
impl FileReaderWithProgress {
450-
pub(crate) fn new_file(path: &Path) -> Result<Self> {
451-
let fh = match File::open(path) {
452-
Ok(fh) => fh,
453-
Err(_) => {
454-
bail!(RustupError::ReadingFile {
455-
name: "downloaded",
456-
path: path.to_path_buf(),
457-
})
458-
}
459-
};
460-
461-
// Inform the tracker of the file size
462-
Ok(FileReaderWithProgress {
463-
fh: BufReader::with_capacity(8 * 1024 * 1024, fh),
464-
nbytes: 0,
465-
})
466-
}
467-
}
468-
469-
impl io::Read for FileReaderWithProgress {
470-
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
471-
match self.fh.read(buf) {
472-
Ok(nbytes) => {
473-
self.nbytes += nbytes as u64;
474-
Ok(nbytes)
475-
}
476-
Err(e) => Err(e),
477-
}
444+
pub(crate) fn buffered(path: &Path) -> Result<BufReader<File>, anyhow::Error> {
445+
match File::open(path) {
446+
Ok(fh) => Ok(BufReader::with_capacity(8 * 1024 * 1024, fh)),
447+
Err(_) => Err(anyhow!(RustupError::ReadingFile {
448+
name: "downloaded",
449+
path: path.to_path_buf(),
450+
})),
478451
}
479452
}
480453

0 commit comments

Comments
 (0)