pub struct Component {
pub root: PathBuf,
pub files: BTreeSet<PathBuf>,
}Expand description
An installable component of an artefact.
A Component describes a subset of
the files in an ExtractedArtefact,
which you may want to install in a target location.
For example,
in order to compile Rust programs,
you will need to install all the files of both
the rustc (compiler) and rust-std (standard library) components
into the same location.
A Component does not store all the relevant files itself,
but just their paths inside
the ExtractedArtefact’s staging area.
Therefore, if you want to use the files described by a Component,
you must ensure the staging area is not cleaned up
before you use them.
§Example
extern crate rust_release_artefact as rra;
use std::fs;
use std::io;
use std::path;
use std::process;
// Assume we have an artefact containing a Cargo component.
let cargo = extracted_artefact.components
.get("cargo")
.ok_or("Artefact does not contain cargo component")?;
// Make sure our destination exists.
let dest_root = path::Path::new("path/to/my/rust/toolchain");
fs::create_dir_all(&dest_root)?;
// Canonicalize our destination path, so Windows can handle long path
// names.
let dest_root = dest_root.canonicalize()?;
// Install it to our target location.
cargo.install_to(&dest_root)?;
// Now we should be able to run Cargo.
process::Command::new(dest_root.join("bin/cargo"))
.arg("build")
.arg("--release")
.spawn()?;
Fields§
§root: PathBufThe absolute filesystem path to the directory containing all the files in the component.
files: BTreeSet<PathBuf>Relative paths from root to each file in the component.
When installing this component, place each file at the same relative path inside the destination directory.
Implementations§
Source§impl Component
impl Component
Sourcepub fn install_to<P: AsRef<Path>>(&self, dest_root: P) -> Result<()>
pub fn install_to<P: AsRef<Path>>(&self, dest_root: P) -> Result<()>
Install this component’s files into the destination directory.
dest_root should be a writable directory,
or a path at which a writable directory may be created.
For each relative path in self.files,
this method constructs a source path by joining it to self.root,
a destination path by joining it to dest_root,
and then installs the file at the source path to the destination.
To increase performance and reduce disk-space usage, this method will attempt to hard-link files rather than copying them. If hard-linking a file is not possible, it will be copied instead.
§Errors
This method will return an error if dest_root
or a directory within it could not be created,
if a destination file already exists
and could not be removed,
or if a file could not be copied.
§Portability
Components may include a deeply-nested directory structure,
which can exceed Windows’ traditional 260 character limit.
It is recommended that you use canonicalize dest_root
before passing it to this method,
since the Windows canonical form
lifts the path length limit to around 32,000 characters.
§Example
See the Component documentation.