diff --git a/build.rs b/build.rs index 86ee9676f5..cd4df060bd 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use std::env; include!("src/dist/triple.rs"); -pub fn from_build() -> Result { +fn from_build() -> Result { let triple = if let Ok(triple) = env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE") { triple } else { diff --git a/src/config.rs b/src/config.rs index a76b438b42..b91b94d21e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -229,7 +229,7 @@ impl Display for PgpPublicKey { pub const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml"; pub struct Cfg { - pub profile_override: Option, + profile_override: Option, pub rustup_dir: PathBuf, pub settings_file: SettingsFile, pub fallback_settings: Option, @@ -376,7 +376,7 @@ impl Cfg { &self.pgp_keys } - pub fn set_profile_override(&mut self, profile: dist::Profile) { + pub(crate) fn set_profile_override(&mut self, profile: dist::Profile) { self.profile_override = Some(profile); } @@ -429,7 +429,7 @@ impl Cfg { // if there is no profile in the settings file. The last variant happens when // a user upgrades from a version of Rustup without profiles to a version of // Rustup with profiles. - pub fn get_profile(&self) -> Result { + pub(crate) fn get_profile(&self) -> Result { if let Some(p) = self.profile_override { return Ok(p); } @@ -986,7 +986,7 @@ impl Cfg { }) } - pub fn get_default_host_triple(&self) -> Result { + pub(crate) fn get_default_host_triple(&self) -> Result { Ok(self .settings_file .with(|s| { diff --git a/src/dist/component/components.rs b/src/dist/component/components.rs index 12da6f0822..3d4cc5c3b9 100644 --- a/src/dist/component/components.rs +++ b/src/dist/component/components.rs @@ -73,7 +73,7 @@ impl Components { }) .collect()) } - pub fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> { + pub(crate) fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> { ComponentBuilder { components: self.clone(), name: name.to_owned(), @@ -85,12 +85,12 @@ impl Components { let result = self.list()?; Ok(result.into_iter().find(|c| (c.name() == name))) } - pub fn prefix(&self) -> InstallPrefix { + pub(crate) fn prefix(&self) -> InstallPrefix { self.prefix.clone() } } -pub struct ComponentBuilder<'a> { +pub(crate) struct ComponentBuilder<'a> { components: Components, name: String, parts: Vec, @@ -98,27 +98,27 @@ pub struct ComponentBuilder<'a> { } impl<'a> ComponentBuilder<'a> { - pub fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> { self.parts .push(ComponentPart("file".to_owned(), path.clone())); self.tx.copy_file(&self.name, path, src) } - pub fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> { self.parts .push(ComponentPart("dir".to_owned(), path.clone())); self.tx.copy_dir(&self.name, path, src) } - pub fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> { self.parts .push(ComponentPart("file".to_owned(), path.clone())); self.tx.move_file(&self.name, path, src) } - pub fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> { self.parts .push(ComponentPart("dir".to_owned(), path.clone())); self.tx.move_dir(&self.name, path, src) } - pub fn finish(mut self) -> Result> { + pub(crate) fn finish(mut self) -> Result> { // Write component manifest let path = self.components.rel_component_manifest(&self.name); let abs_path = self.components.prefix.abs_path(&path); @@ -146,10 +146,10 @@ impl<'a> ComponentBuilder<'a> { pub struct ComponentPart(pub String, pub PathBuf); impl ComponentPart { - pub fn encode(&self) -> String { + pub(crate) fn encode(&self) -> String { format!("{}:{}", &self.0, &self.1.to_string_lossy()) } - pub fn decode(line: &str) -> Option { + pub(crate) fn decode(line: &str) -> Option { line.find(':') .map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..]))) } @@ -162,21 +162,21 @@ pub struct Component { } impl Component { - pub fn manifest_name(&self) -> String { + pub(crate) fn manifest_name(&self) -> String { format!("manifest-{}", &self.name) } - pub fn manifest_file(&self) -> PathBuf { + pub(crate) fn manifest_file(&self) -> PathBuf { self.components.prefix.manifest_file(&self.manifest_name()) } - pub fn rel_manifest_file(&self) -> PathBuf { + pub(crate) fn rel_manifest_file(&self) -> PathBuf { self.components .prefix .rel_manifest_file(&self.manifest_name()) } - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } - pub fn parts(&self) -> Result> { + pub(crate) fn parts(&self) -> Result> { let mut result = Vec::new(); for line in utils::read_file("component", &self.manifest_file())?.lines() { result.push( diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs index db310d3cfc..714f6e0fb7 100644 --- a/src/dist/component/package.rs +++ b/src/dist/component/package.rs @@ -21,8 +21,8 @@ use crate::utils::notifications::Notification; use crate::utils::utils; /// The current metadata revision used by rust-installer -pub const INSTALLER_VERSION: &str = "3"; -pub const VERSION_FILE: &str = "rust-installer-version"; +pub(crate) const INSTALLER_VERSION: &str = "3"; +pub(crate) const VERSION_FILE: &str = "rust-installer-version"; pub trait Package: fmt::Debug { fn contains(&self, component: &str, short_name: Option<&str>) -> bool; @@ -136,7 +136,7 @@ impl Package for DirectoryPackage { } #[derive(Debug)] -pub struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>); +pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>); impl<'a> TarPackage<'a> { pub(crate) fn new( @@ -548,7 +548,7 @@ impl<'a> Package for TarPackage<'a> { } #[derive(Debug)] -pub struct TarGzPackage<'a>(TarPackage<'a>); +pub(crate) struct TarGzPackage<'a>(TarPackage<'a>); impl<'a> TarGzPackage<'a> { pub(crate) fn new( @@ -584,7 +584,7 @@ impl<'a> Package for TarGzPackage<'a> { } #[derive(Debug)] -pub struct TarXzPackage<'a>(TarPackage<'a>); +pub(crate) struct TarXzPackage<'a>(TarPackage<'a>); impl<'a> TarXzPackage<'a> { pub(crate) fn new( @@ -620,7 +620,7 @@ impl<'a> Package for TarXzPackage<'a> { } #[derive(Debug)] -pub struct TarZStdPackage<'a>(TarPackage<'a>); +pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>); impl<'a> TarZStdPackage<'a> { pub(crate) fn new( diff --git a/src/dist/component/transaction.rs b/src/dist/component/transaction.rs index 50b160cdae..2eaf969406 100644 --- a/src/dist/component/transaction.rs +++ b/src/dist/component/transaction.rs @@ -148,7 +148,12 @@ impl<'a> Transaction<'a> { } /// Move a file to a relative path of the install prefix. - pub fn move_file(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn move_file( + &mut self, + component: &str, + relpath: PathBuf, + src: &Path, + ) -> Result<()> { assert!(relpath.is_relative()); let item = ChangedItem::move_file(&self.prefix, component, relpath, src, self.notify_handler())?; @@ -157,7 +162,7 @@ impl<'a> Transaction<'a> { } /// Recursively move a directory to a relative path of the install prefix. - pub fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> { + pub(crate) fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> { assert!(relpath.is_relative()); let item = ChangedItem::move_dir(&self.prefix, component, relpath, src, self.notify_handler())?; @@ -165,7 +170,7 @@ impl<'a> Transaction<'a> { Ok(()) } - pub fn temp(&self) -> &'a temp::Cfg { + pub(crate) fn temp(&self) -> &'a temp::Cfg { self.temp_cfg } pub(crate) fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) { diff --git a/src/dist/config.rs b/src/dist/config.rs index ff10a7d825..744fe215a3 100644 --- a/src/dist/config.rs +++ b/src/dist/config.rs @@ -4,8 +4,8 @@ use super::manifest::Component; use crate::errors::*; use crate::utils::toml_utils::*; -pub const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"]; -pub const DEFAULT_CONFIG_VERSION: &str = "1"; +pub(crate) const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"]; +pub(crate) const DEFAULT_CONFIG_VERSION: &str = "1"; #[derive(Clone, Debug)] pub struct Config { @@ -14,7 +14,7 @@ pub struct Config { } impl Config { - pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result { + pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result { let config_version = get_string(&mut table, "config_version", path)?; if !SUPPORTED_CONFIG_VERSIONS.contains(&&*config_version) { bail!(RustupError::UnsupportedVersion(config_version)); @@ -29,7 +29,7 @@ impl Config { components, }) } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); result.insert( "config_version".to_owned(), @@ -42,12 +42,12 @@ impl Config { result } - pub fn parse(data: &str) -> Result { + pub(crate) fn parse(data: &str) -> Result { let value = toml::from_str(data).context("error parsing manifest")?; Self::from_toml(value, "") } - pub fn stringify(self) -> String { + pub(crate) fn stringify(self) -> String { toml::Value::Table(self.into_toml()).to_string() } @@ -72,7 +72,7 @@ impl Config { result } - pub fn new() -> Self { + pub(crate) fn new() -> Self { Default::default() } } diff --git a/src/dist/dist.rs b/src/dist/dist.rs index 73d435e983..3de23f3572 100644 --- a/src/dist/dist.rs +++ b/src/dist/dist.rs @@ -18,7 +18,7 @@ use crate::dist::manifestation::{Changes, Manifestation, UpdateStatus}; use crate::dist::notifications::*; use crate::dist::prefix::InstallPrefix; use crate::dist::temp; -pub use crate::dist::triple::*; +pub(crate) use crate::dist::triple::*; use crate::errors::RustupError; use crate::process; use crate::utils::utils; @@ -26,7 +26,7 @@ use crate::utils::utils; pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org"; // Deprecated -pub static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist"; +pub(crate) static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist"; // The channel patterns we support static TOOLCHAIN_CHANNELS: &[&str] = &[ @@ -217,7 +217,7 @@ impl TargetTriple { Self(name.to_string()) } - pub fn from_build() -> Self { + pub(crate) fn from_build() -> Self { if let Some(triple) = option_env!("RUSTUP_OVERRIDE_BUILD_TRIPLE") { Self::new(triple) } else { @@ -225,7 +225,7 @@ impl TargetTriple { } } - pub fn from_host() -> Option { + pub(crate) fn from_host() -> Option { #[cfg(windows)] fn inner() -> Option { use std::mem; @@ -308,11 +308,11 @@ impl TargetTriple { } } - pub fn from_host_or_build() -> Self { + pub(crate) fn from_host_or_build() -> Self { Self::from_host().unwrap_or_else(Self::from_build) } - pub fn can_run(&self, other: &TargetTriple) -> Result { + pub(crate) fn can_run(&self, other: &TargetTriple) -> Result { // Most trivial shortcut of all if self == other { return Ok(true); @@ -373,7 +373,7 @@ impl FromStr for PartialToolchainDesc { } impl PartialToolchainDesc { - pub fn resolve(self, input_host: &TargetTriple) -> Result { + pub(crate) fn resolve(self, input_host: &TargetTriple) -> Result { let host = PartialTargetTriple::new(&input_host.0).ok_or_else(|| { anyhow!(format!( "Provided host '{}' couldn't be converted to partial triple", @@ -417,7 +417,7 @@ impl PartialToolchainDesc { }) } - pub fn has_triple(&self) -> bool { + pub(crate) fn has_triple(&self) -> bool { self.target.arch.is_some() || self.target.os.is_some() || self.target.env.is_some() } } @@ -440,7 +440,7 @@ impl FromStr for ToolchainDesc { } impl ToolchainDesc { - pub fn manifest_v1_url(&self, dist_root: &str) -> String { + pub(crate) fn manifest_v1_url(&self, dist_root: &str) -> String { let do_manifest_staging = process().var("RUSTUP_STAGED_MANIFEST").is_ok(); match (self.date.as_ref(), do_manifest_staging) { (None, false) => format!("{}/channel-rust-{}", dist_root, self.channel), @@ -450,7 +450,7 @@ impl ToolchainDesc { } } - pub fn manifest_v2_url(&self, dist_root: &str) -> String { + pub(crate) fn manifest_v2_url(&self, dist_root: &str) -> String { format!("{}.toml", self.manifest_v1_url(dist_root)) } /// Either "$channel" or "channel-$date" @@ -461,25 +461,17 @@ impl ToolchainDesc { } } - pub fn package_dir(&self, dist_root: &str) -> String { + pub(crate) fn package_dir(&self, dist_root: &str) -> String { match self.date { None => dist_root.to_string(), Some(ref date) => format!("{}/{}", dist_root, date), } } - pub fn full_spec(&self) -> String { - if self.date.is_some() { - format!("{}", self) - } else { - format!("{} (tracking)", self) - } - } - /// Toolchain channels are considered 'tracking' if it is one of the named channels /// such as `stable`, or is an incomplete version such as `1.48`, and the /// date field is empty. - pub fn is_tracking(&self) -> bool { + pub(crate) fn is_tracking(&self) -> bool { let channels = ["nightly", "beta", "stable"]; lazy_static! { static ref TRACKING_VERSION: Regex = Regex::new(r"^\d{1}\.\d{1,3}$").unwrap(); @@ -490,7 +482,7 @@ impl ToolchainDesc { } // A little convenience for just parsing a channel name or archived channel name -pub fn validate_channel_name(name: &str) -> Result<()> { +pub(crate) fn validate_channel_name(name: &str) -> Result<()> { let toolchain = PartialToolchainDesc::from_str(name)?; if toolchain.has_triple() { Err(anyhow!(format!("target triple in channel name '{}'", name))) @@ -500,7 +492,7 @@ pub fn validate_channel_name(name: &str) -> Result<()> { } #[derive(Debug)] -pub struct Manifest<'a>(temp::File<'a>, String); +pub(crate) struct Manifest<'a>(temp::File<'a>, String); #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] pub enum Profile { @@ -527,11 +519,11 @@ impl FromStr for Profile { } impl Profile { - pub fn names() -> &'static [&'static str] { + pub(crate) fn names() -> &'static [&'static str] { &["minimal", "default", "complete"] } - pub fn default_name() -> &'static str { + pub(crate) fn default_name() -> &'static str { "default" } } @@ -592,7 +584,7 @@ impl fmt::Display for Profile { } } -pub fn valid_profile_names() -> String { +pub(crate) fn valid_profile_names() -> String { Profile::names() .iter() .map(|s| format!("'{}'", s)) @@ -605,7 +597,7 @@ pub fn valid_profile_names() -> String { // an upgrade then all the existing components will be upgraded. // // Returns the manifest's hash if anything changed. -pub fn update_from_dist<'a>( +pub(crate) fn update_from_dist<'a>( download: DownloadCfg<'a>, update_hash: Option<&Path>, toolchain: &ToolchainDesc, @@ -975,7 +967,7 @@ fn try_update_from_dist_<'a>( } } -pub fn dl_v2_manifest<'a>( +pub(crate) fn dl_v2_manifest<'a>( download: DownloadCfg<'a>, update_hash: Option<&Path>, toolchain: &ToolchainDesc, diff --git a/src/dist/download.rs b/src/dist/download.rs index cf00b3a5a1..97055349e4 100644 --- a/src/dist/download.rs +++ b/src/dist/download.rs @@ -23,7 +23,7 @@ pub struct DownloadCfg<'a> { pub pgp_keys: &'a [PgpPublicKey], } -pub struct File { +pub(crate) struct File { path: PathBuf, } @@ -40,7 +40,7 @@ impl<'a> DownloadCfg<'a> { /// Partial downloads are stored in `self.download_dir`, keyed by hash. If the /// target file already exists, then the hash is checked and it is returned /// immediately without re-downloading. - pub fn download(&self, url: &Url, hash: &str) -> Result { + pub(crate) fn download(&self, url: &Url, hash: &str) -> Result { utils::ensure_dir_exists( "Download Directory", self.download_dir, @@ -116,7 +116,7 @@ impl<'a> DownloadCfg<'a> { } } - pub fn clean(&self, hashes: &[String]) -> Result<()> { + pub(crate) fn clean(&self, hashes: &[String]) -> Result<()> { for hash in hashes.iter() { let used_file = self.download_dir.join(hash); if self.download_dir.join(&used_file).exists() { @@ -182,7 +182,7 @@ impl<'a> DownloadCfg<'a> { /// and if they match, the download is skipped. /// Verifies the signature found at the same url with a `.asc` suffix, and prints a /// warning when the signature does not verify, or is not found. - pub fn download_and_check( + pub(crate) fn download_and_check( &self, url_str: &str, update_hash: Option<&Path>, diff --git a/src/dist/manifest.rs b/src/dist/manifest.rs index 595e97b865..9fe38ea33f 100644 --- a/src/dist/manifest.rs +++ b/src/dist/manifest.rs @@ -22,17 +22,16 @@ use crate::dist::dist::{PartialTargetTriple, Profile, TargetTriple}; use crate::errors::*; use crate::utils::toml_utils::*; -pub const SUPPORTED_MANIFEST_VERSIONS: [&str; 1] = ["2"]; -pub const DEFAULT_MANIFEST_VERSION: &str = "2"; +pub(crate) const SUPPORTED_MANIFEST_VERSIONS: [&str; 1] = ["2"]; #[derive(Clone, Debug, PartialEq)] pub struct Manifest { - pub manifest_version: String, + manifest_version: String, pub date: String, pub packages: HashMap, pub renames: HashMap, pub reverse_renames: HashMap, - pub profiles: HashMap>, + profiles: HashMap>, } #[derive(Clone, Debug, PartialEq)] @@ -121,7 +120,7 @@ impl Manifest { toml::Value::Table(self.into_toml()).to_string() } - pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result { + pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result { let version = get_string(&mut table, "manifest-version", path)?; if !SUPPORTED_MANIFEST_VERSIONS.contains(&&*version) { bail!(RustupError::UnsupportedVersion(version)); @@ -136,7 +135,7 @@ impl Manifest { profiles: Self::table_to_profiles(&mut table, path)?, }) } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); result.insert("date".to_owned(), toml::Value::String(self.date)); @@ -248,11 +247,11 @@ impl Manifest { .ok_or_else(|| anyhow!(format!("package not found: '{}'", name))) } - pub fn get_rust_version(&self) -> Result<&str> { + pub(crate) fn get_rust_version(&self) -> Result<&str> { self.get_package("rust").map(|p| &*p.version) } - pub fn get_legacy_components(&self, target: &TargetTriple) -> Result> { + pub(crate) fn get_legacy_components(&self, target: &TargetTriple) -> Result> { // Build a profile from the components/extensions. let result = self .get_package("rust")? @@ -340,7 +339,7 @@ impl Manifest { // If the component should be renamed by this manifest, then return a new // component with the new name. If not, return `None`. - pub fn rename_component(&self, component: &Component) -> Option { + pub(crate) fn rename_component(&self, component: &Component) -> Option { self.renames.get(&component.pkg).map(|r| { let mut c = component.clone(); c.pkg = r.clone(); @@ -350,13 +349,13 @@ impl Manifest { } impl Package { - pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result { + pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result { Ok(Self { version: get_string(&mut table, "version", path)?, targets: Self::toml_to_targets(table, path)?, }) } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); result.insert("version".to_owned(), toml::Value::String(self.version)); @@ -417,7 +416,7 @@ impl Package { } impl PackageTargets { - pub fn get<'a>(&'a self, target: &TargetTriple) -> Option<&'a TargetedPackage> { + pub(crate) fn get<'a>(&'a self, target: &TargetTriple) -> Option<&'a TargetedPackage> { match self { Self::Wildcard(tpkg) => Some(tpkg), Self::Targeted(tpkgs) => tpkgs.get(target), @@ -432,7 +431,7 @@ impl PackageTargets { } impl TargetedPackage { - pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result { + pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result { let components = get_array(&mut table, "components", path)?; let extensions = get_array(&mut table, "extensions", path)?; @@ -463,7 +462,7 @@ impl TargetedPackage { }) } } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); let (components, extensions) = Self::components_to_toml(self.components); if !components.is_empty() { @@ -529,7 +528,7 @@ impl Component { } } - pub fn new_with_target(pkg_with_target: &str, is_extension: bool) -> Option { + pub(crate) fn new_with_target(pkg_with_target: &str, is_extension: bool) -> Option { use std::convert::TryFrom; for (pos, _) in pkg_with_target.match_indices('-') { let pkg = &pkg_with_target[0..pos]; @@ -547,14 +546,14 @@ impl Component { None } - pub fn wildcard(&self) -> Self { + pub(crate) fn wildcard(&self) -> Self { Self { pkg: self.pkg.clone(), target: None, is_extension: false, } } - pub fn from_toml( + pub(crate) fn from_toml( mut table: toml::value::Table, path: &str, is_extension: bool, @@ -571,7 +570,7 @@ impl Component { is_extension, }) } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); result.insert( "target".to_owned(), @@ -584,7 +583,7 @@ impl Component { result.insert("pkg".to_owned(), toml::Value::String(self.pkg)); result } - pub fn name(&self, manifest: &Manifest) -> String { + pub(crate) fn name(&self, manifest: &Manifest) -> String { let pkg = self.short_name(manifest); if let Some(ref t) = self.target { format!("{}-{}", pkg, t) @@ -592,14 +591,14 @@ impl Component { pkg } } - pub fn short_name(&self, manifest: &Manifest) -> String { + pub(crate) fn short_name(&self, manifest: &Manifest) -> String { if let Some(from) = manifest.reverse_renames.get(&self.pkg) { from.to_owned() } else { self.pkg.clone() } } - pub fn description(&self, manifest: &Manifest) -> String { + pub(crate) fn description(&self, manifest: &Manifest) -> String { let pkg = self.short_name(manifest); if let Some(ref t) = self.target { format!("'{}' for target '{}'", pkg, t) @@ -610,7 +609,7 @@ impl Component { pub fn short_name_in_manifest(&self) -> &String { &self.pkg } - pub fn name_in_manifest(&self) -> String { + pub(crate) fn name_in_manifest(&self) -> String { let pkg = self.short_name_in_manifest(); if let Some(ref t) = self.target { format!("{}-{}", pkg, t) @@ -618,7 +617,7 @@ impl Component { pkg.to_string() } } - pub fn target(&self) -> String { + pub(crate) fn target(&self) -> String { if let Some(t) = self.target.as_ref() { t.to_string() } else { @@ -626,7 +625,7 @@ impl Component { } } - pub fn contained_within(&self, components: &[Component]) -> bool { + pub(crate) fn contained_within(&self, components: &[Component]) -> bool { if components.contains(self) { // Yes, we're within the component set, move on true diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index a0efcdcbbc..7fb33df053 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -22,8 +22,8 @@ use crate::errors::{OperationError, RustupError}; use crate::process; use crate::utils::utils; -pub const DIST_MANIFEST: &str = "multirust-channel-manifest.toml"; -pub const CONFIG_FILE: &str = "multirust-config.toml"; +pub(crate) const DIST_MANIFEST: &str = "multirust-channel-manifest.toml"; +pub(crate) const CONFIG_FILE: &str = "multirust-config.toml"; #[derive(Debug)] pub struct Manifestation { @@ -38,13 +38,6 @@ pub struct Changes { } impl Changes { - pub fn none() -> Self { - Self { - explicit_add_components: Vec::new(), - remove_components: Vec::new(), - } - } - fn iter_add_components(&self) -> impl Iterator { self.explicit_add_components.iter() } @@ -355,7 +348,7 @@ impl Manifestation { // Read the config file. Config files are presently only created // for v2 installations. - pub fn read_config(&self) -> Result> { + pub(crate) fn read_config(&self) -> Result> { let prefix = self.installation.prefix(); let rel_config_path = prefix.rel_manifest_file(CONFIG_FILE); let config_path = prefix.path().join(rel_config_path); diff --git a/src/dist/mod.rs b/src/dist/mod.rs index ec7026fedf..36d05f1c08 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -5,13 +5,13 @@ pub use crate::dist::notifications::Notification; pub mod temp; pub mod component; -pub mod config; +pub(crate) mod config; #[allow(clippy::module_inception)] pub mod dist; pub mod download; pub mod manifest; pub mod manifestation; -pub mod notifications; +pub(crate) mod notifications; pub mod prefix; -pub mod signatures; -pub mod triple; +pub(crate) mod signatures; +pub(crate) mod triple; diff --git a/src/dist/prefix.rs b/src/dist/prefix.rs index 83897a5c96..76d03461b9 100644 --- a/src/dist/prefix.rs +++ b/src/dist/prefix.rs @@ -13,10 +13,10 @@ impl InstallPrefix { pub fn path(&self) -> &Path { &self.path } - pub fn abs_path>(&self, path: P) -> PathBuf { + pub(crate) fn abs_path>(&self, path: P) -> PathBuf { self.path.join(path) } - pub fn manifest_dir(&self) -> PathBuf { + pub(crate) fn manifest_dir(&self) -> PathBuf { let mut path = self.path.clone(); path.push(REL_MANIFEST_DIR); path @@ -26,7 +26,7 @@ impl InstallPrefix { path.push(name); path } - pub fn rel_manifest_file(&self, name: &str) -> PathBuf { + pub(crate) fn rel_manifest_file(&self, name: &str) -> PathBuf { let mut path = PathBuf::from(REL_MANIFEST_DIR); path.push(name); path diff --git a/src/dist/signatures.rs b/src/dist/signatures.rs index 0b3a0b927c..909dc801f4 100644 --- a/src/dist/signatures.rs +++ b/src/dist/signatures.rs @@ -10,7 +10,7 @@ use pgp::{Deserializable, StandaloneSignature}; use crate::config::PgpPublicKey; -pub fn verify_signature( +pub(crate) fn verify_signature( mut content: T, signature: &str, keys: &[PgpPublicKey], diff --git a/src/dist/temp.rs b/src/dist/temp.rs index 96a342f105..8c8a9b3b99 100644 --- a/src/dist/temp.rs +++ b/src/dist/temp.rs @@ -4,7 +4,7 @@ use std::io; use std::ops; use std::path::{Path, PathBuf}; -pub use anyhow::{Context, Result}; +pub(crate) use anyhow::{Context, Result}; use thiserror::Error as ThisError; use crate::utils::notify::NotificationLevel; @@ -12,13 +12,13 @@ use crate::utils::raw; use crate::utils::utils; #[derive(Debug, ThisError)] -pub enum Error { +pub(crate) enum CreatingError { #[error("could not create temp root {}" ,.0.display())] - CreatingRoot(PathBuf), + Root(PathBuf), #[error("could not create temp file {}",.0.display())] - CreatingFile(PathBuf), + File(PathBuf), #[error("could not create temp directory {}",.0.display())] - CreatingDirectory(PathBuf), + Directory(PathBuf), } #[derive(Debug)] @@ -37,7 +37,7 @@ pub struct Cfg { } #[derive(Debug)] -pub struct Dir<'a> { +pub(crate) struct Dir<'a> { cfg: &'a Cfg, path: PathBuf, } @@ -102,14 +102,14 @@ impl Cfg { } } - pub fn create_root(&self) -> Result { + pub(crate) fn create_root(&self) -> Result { raw::ensure_dir_exists(&self.root_directory, |p| { (self.notify_handler)(Notification::CreatingRoot(p)); }) - .with_context(|| Error::CreatingRoot(PathBuf::from(&self.root_directory))) + .with_context(|| CreatingError::Root(PathBuf::from(&self.root_directory))) } - pub fn new_directory(&self) -> Result> { + pub(crate) fn new_directory(&self) -> Result> { self.create_root()?; loop { @@ -122,7 +122,7 @@ impl Cfg { if !raw::path_exists(&temp_dir) { (self.notify_handler)(Notification::CreatingDirectory(&temp_dir)); fs::create_dir(&temp_dir) - .with_context(|| Error::CreatingDirectory(PathBuf::from(&temp_dir)))?; + .with_context(|| CreatingError::Directory(PathBuf::from(&temp_dir)))?; return Ok(Dir { cfg: self, path: temp_dir, @@ -135,7 +135,7 @@ impl Cfg { self.new_file_with_ext("", "") } - pub fn new_file_with_ext(&self, prefix: &str, ext: &str) -> Result> { + pub(crate) fn new_file_with_ext(&self, prefix: &str, ext: &str) -> Result> { self.create_root()?; loop { @@ -148,7 +148,7 @@ impl Cfg { if !raw::path_exists(&temp_file) { (self.notify_handler)(Notification::CreatingFile(&temp_file)); fs::File::create(&temp_file) - .with_context(|| Error::CreatingFile(PathBuf::from(&temp_file)))?; + .with_context(|| CreatingError::File(PathBuf::from(&temp_file)))?; return Ok(File { cfg: self, path: temp_file, @@ -157,7 +157,7 @@ impl Cfg { } } - pub fn clean(&self) { + pub(crate) fn clean(&self) { utils::delete_dir_contents(&self.root_directory); } } diff --git a/src/dist/triple.rs b/src/dist/triple.rs index ef7c4e4740..07496bc705 100644 --- a/src/dist/triple.rs +++ b/src/dist/triple.rs @@ -54,7 +54,7 @@ pub struct PartialTargetTriple { } impl PartialTargetTriple { - pub fn new(name: &str) -> Option { + pub(crate) fn new(name: &str) -> Option { if name.is_empty() { return Some(Self { arch: None, diff --git a/src/toolchain.rs b/src/toolchain.rs index db0c15d46d..a9963a83b6 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -528,7 +528,7 @@ impl<'a> DistributableToolchain<'a> { } // Installed only. - pub fn add_component(&self, mut component: Component) -> Result<()> { + pub(crate) fn add_component(&self, mut component: Component) -> Result<()> { if !self.0.exists() { return Err(RustupError::ToolchainNotInstalled(self.0.name.to_owned()).into()); } @@ -643,7 +643,7 @@ impl<'a> DistributableToolchain<'a> { } // Installed and not-installed? - pub fn desc(&self) -> Result { + pub(crate) fn desc(&self) -> Result { ToolchainDesc::from_str(&self.0.name) } @@ -736,7 +736,7 @@ impl<'a> DistributableToolchain<'a> { } // Installed only. - pub fn get_manifest(&self) -> Result> { + pub(crate) fn get_manifest(&self) -> Result> { if !self.0.exists() { bail!(RustupError::ToolchainNotInstalled(self.0.name().to_owned())); } @@ -751,7 +751,7 @@ impl<'a> DistributableToolchain<'a> { } // Not installed only? - pub fn install_from_dist( + pub(crate) fn install_from_dist( &self, force_update: bool, allow_downgrade: bool, @@ -872,7 +872,7 @@ impl<'a> DistributableToolchain<'a> { } // Installed only. - pub fn remove_component(&self, mut component: Component) -> Result<()> { + pub(crate) fn remove_component(&self, mut component: Component) -> Result<()> { // Overlapping code with get_manifest :/. if !self.0.exists() { return Err(RustupError::ToolchainNotInstalled(self.0.name.to_owned()).into());