Skip to content

Commit ed3de60

Browse files
committed
dist: store package directory once
1 parent a8fc697 commit ed3de60

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/dist/component/package.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ pub(crate) const INSTALLER_VERSION: &str = "3";
2828
pub(crate) const VERSION_FILE: &str = "rust-installer-version";
2929

3030
#[derive(Debug)]
31-
pub struct DirectoryPackage {
32-
path: PathBuf,
31+
pub struct DirectoryPackage<P> {
32+
path: P,
3333
components: HashSet<String>,
3434
copy: bool,
3535
}
3636

37-
impl DirectoryPackage {
38-
pub fn new(path: PathBuf, copy: bool) -> Result<Self> {
37+
impl<P: Deref<Target = Path>> DirectoryPackage<P> {
38+
pub fn new(path: P, copy: bool) -> Result<Self> {
3939
let file = utils::read_file("installer version", &path.join(VERSION_FILE))?;
4040
let v = file.trim();
4141
if v != INSTALLER_VERSION {
@@ -117,8 +117,7 @@ impl DirectoryPackage {
117117
}
118118

119119
#[derive(Debug)]
120-
#[allow(dead_code)] // temp::Dir is held for drop.
121-
pub(crate) struct TarPackage(DirectoryPackage, temp::Dir);
120+
pub(crate) struct TarPackage(DirectoryPackage<temp::Dir>);
122121

123122
impl TarPackage {
124123
pub(crate) fn compressed<R: Read>(
@@ -142,15 +141,12 @@ impl TarPackage {
142141
unpack_without_first_dir(&mut archive, &temp_dir, dl_cfg)
143142
.context("failed to extract package")?;
144143

145-
Ok(TarPackage(
146-
DirectoryPackage::new(temp_dir.to_owned(), false)?,
147-
temp_dir,
148-
))
144+
Ok(TarPackage(DirectoryPackage::new(temp_dir, false)?))
149145
}
150146
}
151147

152148
impl Deref for TarPackage {
153-
type Target = DirectoryPackage;
149+
type Target = DirectoryPackage<temp::Dir>;
154150

155151
fn deref(&self) -> &Self::Target {
156152
&self.0

src/test/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ impl DistContext {
5454
})
5555
}
5656

57-
pub fn start(&self) -> anyhow::Result<(Transaction<'_>, Components, DirectoryPackage)> {
57+
pub fn start(&self) -> anyhow::Result<(Transaction<'_>, Components, DirectoryPackage<&Path>)> {
5858
let tx = self.transaction();
5959
let components = Components::open(self.prefix.clone())?;
60-
let pkg = DirectoryPackage::new(self.pkg_dir.path().to_owned(), true)?;
60+
let pkg = DirectoryPackage::new(self.pkg_dir.path(), true)?;
6161
Ok((tx, components, pkg))
6262
}
6363

0 commit comments

Comments
 (0)