Skip to content

Commit 92a688f

Browse files
committed
utils: drop unused reader tracking
1 parent fcd02c0 commit 92a688f

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;
@@ -321,8 +322,7 @@ impl DownloadStatus {
321322

322323
fn file_hash(path: &Path) -> Result<String> {
323324
let mut hasher = Sha256::new();
324-
let mut downloaded = utils::FileReaderWithProgress::new_file(path)?;
325-
use std::io::Read;
325+
let mut downloaded = utils::buffered(path)?;
326326
let mut buf = vec![0; 32768];
327327
while let Ok(n) = downloaded.read(&mut buf) {
328328
if n == 0 {

src/dist/manifestation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl Manifestation {
407407
}
408408

409409
// Install all the components in the installer
410-
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
410+
let reader = utils::buffered(&installer_file)?;
411411
let package = DirectoryPackage::compressed(reader, CompressionKind::GZip, dl_cfg)?;
412412
for component in package.components() {
413413
tx = package.install(&self.installation, &component, None, tx)?;
@@ -722,7 +722,7 @@ impl<'a> ComponentBinary<'a> {
722722

723723
self.status.installing();
724724

725-
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
725+
let reader = utils::buffered(&installer_file)?;
726726
let package =
727727
DirectoryPackage::compressed(reader, self.binary.compression, self.download_cfg)?;
728728

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};
@@ -444,40 +444,13 @@ pub(crate) fn delete_dir_contents_following_links(dir_path: &Path) {
444444
}
445445
}
446446

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

0 commit comments

Comments
 (0)