Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
//! `Components` and `DirectoryPackage` are the two sides of the
//! installation / uninstallation process.

use std::borrow::Cow;
use std::convert::Infallible;
use std::fmt;
use std::io::BufWriter;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{
borrow::Cow,
convert::Infallible,
fmt,
io::BufWriter,
path::{Path, PathBuf},
str::FromStr,
};

use anyhow::bail;

use crate::dist::component::package::{INSTALLER_VERSION, VERSION_FILE};
use crate::dist::component::transaction::Transaction;
use crate::dist::prefix::InstallPrefix;
use crate::errors::RustupError;
use crate::utils;
use crate::{
dist::{
component::{
package::{INSTALLER_VERSION, VERSION_FILE},
transaction::Transaction,
},
prefix::InstallPrefix,
},
errors::RustupError,
utils,
};

const COMPONENTS_FILE: &str = "components";

Expand Down
32 changes: 20 additions & 12 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
//! for installing from a directory or tarball to an installation
//! prefix, represented by a `Components` instance.

use std::collections::{HashMap, HashSet};
use std::io::{self, BufRead, ErrorKind as IOErrorKind, Read};
use std::mem;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::{
collections::{HashMap, HashSet},
io::{self, BufRead, ErrorKind as IOErrorKind, Read},
mem,
ops::Deref,
path::{Path, PathBuf},
};

use anyhow::{Context, anyhow, bail};
use tar::EntryType;
use tracing::warn;

use crate::diskio::{ChunkWriter, CompletedIo, Executor, IO_CHUNK_SIZE, Item, Kind};
use crate::dist::component::components::{ComponentPart, ComponentPartKind, Components};
use crate::dist::component::transaction::Transaction;
use crate::dist::manifest::CompressionKind;
use crate::dist::temp;
use crate::errors::RustupError;
use crate::utils;
use crate::{
diskio::{ChunkWriter, CompletedIo, Executor, IO_CHUNK_SIZE, Item, Kind},
dist::{
component::{
components::{ComponentPart, ComponentPartKind, Components},
transaction::Transaction,
},
manifest::CompressionKind,
temp,
},
errors::RustupError,
utils,
};

/// The current metadata revision used by rust-installer
pub(crate) const INSTALLER_VERSION: &str = "3";
Expand Down
12 changes: 6 additions & 6 deletions src/dist/component/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::{fs, io::Write, path::PathBuf};

use crate::errors::RustupError;
use crate::test::DistContext;
use crate::utils::{self, raw as utils_raw};
use crate::{
errors::RustupError,
test::DistContext,
utils::{self, raw as utils_raw},
};

#[test]
fn add_file() {
Expand Down
17 changes: 10 additions & 7 deletions src/dist/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
//! FIXME: This uses ensure_dir_exists in some places but rollback
//! does not remove any dirs created by it.

use std::fs::File;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::{
fs::File,
path::{Path, PathBuf},
sync::Arc,
};

use anyhow::{Context, anyhow};
use tracing::{error, info};

use crate::dist::prefix::InstallPrefix;
use crate::dist::temp;
use crate::errors::RustupError;
use crate::utils;
use crate::{
dist::{prefix::InstallPrefix, temp},
errors::RustupError,
utils,
};

/// A Transaction tracks changes to the file system, allowing them to
/// be rolled back in case of an error. Instead of deleting or
Expand Down
3 changes: 1 addition & 2 deletions src/dist/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt;
use std::str::FromStr;
use std::{fmt, str::FromStr};

use anyhow::Context;
use serde::{Deserialize, Serialize};
Expand Down
35 changes: 21 additions & 14 deletions src/dist/download.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
use std::borrow::Cow;
use std::fs;
use std::io::Read;
use std::ops;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use std::{
borrow::Cow,
fs,
io::Read,
ops,
path::{Path, PathBuf},
sync::{Arc, Mutex},
time::{Duration, Instant},
};

use anyhow::{Context, anyhow};
use indicatif::{MultiProgress, ProgressBar, ProgressBarIter, ProgressDrawTarget, ProgressStyle};
use sha2::{Digest, Sha256};
use tracing::{debug, info, warn};
use url::Url;

use crate::config::Cfg;
use crate::dist::manifest::{Manifest, ManifestWithHash};
use crate::dist::{Channel, DEFAULT_DIST_SERVER, ToolchainDesc, temp};
use crate::download::{DownloadOptions, is_network_failure};
use crate::errors::RustupError;
use crate::process::Process;
use crate::utils;
use crate::{
config::Cfg,
dist::{
Channel, DEFAULT_DIST_SERVER, ToolchainDesc,
manifest::{Manifest, ManifestWithHash},
temp,
},
download::{DownloadOptions, is_network_failure},
errors::RustupError,
process::Process,
utils,
};

const UPDATE_HASH_LEN: usize = 20;

Expand Down
10 changes: 6 additions & 4 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ impl Hash for Component {
}

mod component_target {
use super::TargetTuple;
use serde::{Deserialize, Deserializer, Serializer};

use super::TargetTuple;

pub fn serialize<S: Serializer>(
target: &Option<TargetTuple>,
serializer: S,
Expand Down Expand Up @@ -660,9 +661,10 @@ impl fmt::Display for ManifestVersion {

#[cfg(test)]
mod tests {
use crate::RustupError;
use crate::dist::TargetTuple;
use crate::dist::manifest::Manifest;
use crate::{
RustupError,
dist::{TargetTuple, manifest::Manifest},
};

// Example manifest from https://public.etherpad-mozilla.org/p/Rust-infra-work-week
static EXAMPLE: &str = include_str!("manifest/tests/channel-rust-nightly-example.toml");
Expand Down
8 changes: 5 additions & 3 deletions src/dist/temp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::path::{Path, PathBuf};
use std::{fmt, fs, ops};
use std::{
fmt, fs, ops,
path::{Path, PathBuf},
};

pub(crate) use anyhow::Context as _;
use anyhow::Context as _;
use thiserror::Error as ThisError;
use tracing::{debug, warn};

Expand Down
20 changes: 11 additions & 9 deletions src/process.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
use std::ffi::OsString;
use std::fmt::Debug;
use std::io;
use std::io::IsTerminal;
use std::num::NonZero;
use std::path::PathBuf;
use std::str::FromStr;
#[cfg(feature = "test")]
use std::{
collections::HashMap,
Expand All @@ -14,7 +7,16 @@ use std::{
sync::{Arc, Mutex},
time::{Duration, Instant},
};
use std::{env, thread};
use std::{
env,
ffi::{OsStr, OsString},
fmt::Debug,
io::{self, IsTerminal},
num::NonZero,
path::PathBuf,
str::FromStr,
thread,
};

use anstream::ColorChoice;
use anyhow::{Context, bail};
Expand Down Expand Up @@ -58,7 +60,7 @@ impl Process {

arg0.as_ref()
.and_then(|a| a.file_stem())
.and_then(std::ffi::OsStr::to_str)
.and_then(OsStr::to_str)
.map(String::from)
}

Expand Down
39 changes: 22 additions & 17 deletions src/test/dist.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
//! Tools for building and working with the filesystem of a mock Rust
//! distribution server, with v1 and v2 manifests.

use std::collections::{BTreeMap, HashMap};
use std::fs::{self, File};
use std::io::{self, Read, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, Mutex};
use std::{
collections::{BTreeMap, HashMap},
fs::{self, File},
io::{self, Read, Write},
path::{Path, PathBuf},
sync::{Arc, LazyLock, Mutex},
};

use url::Url;

use super::clitools::hard_link;
use super::mock::MockInstallerBuilder;
use super::{CROSS_ARCH1, CROSS_ARCH2, MULTI_ARCH1, create_hash, this_host_tuple};
use crate::dist::{
DEFAULT_DIST_SERVER, Profile, TargetTuple,
component::{Components, DirectoryPackage, Transaction},
manifest::{
Component, CompressionKind, HashedBinary, Manifest, ManifestVersion, Package,
PackageTargets, Renamed, TargetedPackage,
use super::{
CROSS_ARCH1, CROSS_ARCH2, MULTI_ARCH1, clitools::hard_link, create_hash,
mock::MockInstallerBuilder, this_host_tuple,
};
use crate::{
dist::{
DEFAULT_DIST_SERVER, Profile, TargetTuple,
component::{Components, DirectoryPackage, Transaction},
manifest::{
Component, CompressionKind, HashedBinary, Manifest, ManifestVersion, Package,
PackageTargets, Renamed, TargetedPackage,
},
prefix::InstallPrefix,
temp,
},
prefix::InstallPrefix,
temp,
process::TestProcess,
};
use crate::process::TestProcess;

pub struct DistContext {
pub pkg_dir: tempfile::TempDir,
Expand Down
25 changes: 6 additions & 19 deletions src/test/mock_bin_src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,17 @@ fn main() {
writeln!(out, "{}", arg.to_string_lossy()).unwrap();
}
}
Some("--echo-path") => {
let mut out = io::stderr();
writeln!(out, "{}", std::env::var("PATH").unwrap()).unwrap();
}
Some("--echo-cargo-env") => {
let mut out = io::stderr();
if let Ok(cargo) = std::env::var("CARGO") {
writeln!(out, "{cargo}").unwrap();
} else {
panic!("CARGO environment variable not set");
}
Some("--echo-env") => {
let name = args.next().expect("--echo-env requires a variable name");
let value = env::var(&name).unwrap_or_else(|_| {
panic!("{} environment variable not set", name.to_string_lossy())
});
eprintln!("{value}");
}
Some("--echo-current-exe") => {
let mut out = io::stderr();
writeln!(out, "{}", std::env::current_exe().unwrap().display()).unwrap();
}
Some("--echo-rustup-toolchain-source") => {
let mut out = io::stderr();
if let Ok(rustup_toolchain_source) = std::env::var("RUSTUP_TOOLCHAIN_SOURCE") {
writeln!(out, "{rustup_toolchain_source}").unwrap();
} else {
panic!("RUSTUP_TOOLCHAIN_SOURCE environment variable not set");
}
}
arg => panic!("bad mock proxy commandline: {:?}", arg),
}
}
Expand Down
Loading
Loading