Skip to content

Commit b74fb6d

Browse files
committed
dist: clarify dependency on unpack RAM budget
1 parent 38a056a commit b74fb6d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/dist/component/package.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
55
use std::collections::{HashMap, HashSet};
66
use std::io::{self, ErrorKind as IOErrorKind, Read};
7-
use std::mem;
87
use std::ops::Deref;
98
use std::path::{Path, PathBuf};
109
use std::sync::OnceLock;
10+
use std::{env, mem};
1111

1212
use anyhow::{Context, Result, anyhow, bail};
1313
use tar::EntryType;
@@ -149,7 +149,7 @@ fn unpack_ram(
149149
io_chunk_size: usize,
150150
effective_max_ram: Option<usize>,
151151
dl_cfg: &DownloadCfg<'_>,
152-
) -> usize {
152+
) -> Result<usize, env::VarError> {
153153
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS: usize = 200 * 1024 * 1024;
154154
let minimum_ram = io_chunk_size * 2;
155155
let default_max_unpack_ram = if let Some(effective_max_ram) = effective_max_ram {
@@ -162,12 +162,7 @@ fn unpack_ram(
162162
// Rustup does not know how much RAM the machine has: use the minimum
163163
minimum_ram
164164
};
165-
let unpack_ram = match dl_cfg
166-
.process
167-
.var("RUSTUP_UNPACK_RAM")
168-
.ok()
169-
.and_then(|budget_str| budget_str.parse::<usize>().ok())
170-
{
165+
let unpack_ram = match dl_cfg.process.unpack_ram()? {
171166
Some(budget) => {
172167
if budget < minimum_ram {
173168
warn!(
@@ -196,7 +191,7 @@ fn unpack_ram(
196191
if minimum_ram > unpack_ram {
197192
panic!("RUSTUP_UNPACK_RAM must be larger than {minimum_ram}");
198193
} else {
199-
unpack_ram
194+
Ok(unpack_ram)
200195
}
201196
}
202197

@@ -284,7 +279,7 @@ fn unpack_without_first_dir<R: Read>(
284279
None
285280
}
286281
};
287-
let unpack_ram = unpack_ram(IO_CHUNK_SIZE, effective_max_ram, dl_cfg);
282+
let unpack_ram = unpack_ram(IO_CHUNK_SIZE, effective_max_ram, dl_cfg)?;
288283
let mut io_executor = get_executor(unpack_ram, dl_cfg.process.io_thread_count()?);
289284

290285
let mut directories: HashMap<PathBuf, DirStatus> = HashMap::new();

src/process.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ impl Process {
8989
})
9090
}
9191

92+
pub(crate) fn unpack_ram(&self) -> Result<Option<usize>, env::VarError> {
93+
Ok(match self.var_opt("RUSTUP_UNPACK_RAM")? {
94+
Some(budget) => usize::from_str(&budget).ok(),
95+
None => None,
96+
})
97+
}
98+
9299
pub fn var_opt(&self, key: &str) -> Result<Option<String>, env::VarError> {
93100
match self.var(key) {
94101
Ok(val) => Ok(Some(val)),

0 commit comments

Comments
 (0)