Skip to content

Commit 6ddfda2

Browse files
committed
fix: autoswitching now occurs on install, resolve package into id instead of alias
1 parent ac2a3be commit 6ddfda2

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/repo/versions.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ fn hash_package(package_manifest: &PackageManifest, hash_kind: HashKind) -> Resu
1919
///
2020
/// - Filesystem errors (Out of space, Permissions)
2121
/// - Invalid Repository/Package manifest
22-
pub fn install_version(repo_path: &Path, package_id: &str, chunk_store_path: &Path) -> Result<()> {
22+
///
23+
/// # Returns
24+
///
25+
/// Returns the hash of the installed package
26+
pub fn install_version(
27+
repo_path: &Path,
28+
package_id: &str,
29+
chunk_store_path: &Path,
30+
) -> Result<String> {
2331
let repo_manifest = read_manifest(repo_path)?;
2432

2533
let package_manifest = get_package(&repo_manifest, package_id)
@@ -37,14 +45,22 @@ pub fn install_version(repo_path: &Path, package_id: &str, chunk_store_path: &Pa
3745
serde_yaml::to_string(&package_manifest)?,
3846
)?;
3947

40-
Ok(())
48+
Ok(package_hash)
4149
}
4250

43-
pub fn switch_version(repo_path: &Path, hash: String, package_id: &str) -> Result<()> {
51+
/// Switch to an older version/package hash.
52+
///
53+
/// # Errors
54+
///
55+
/// - Filesystem error during symlink (Within repo directory)
56+
pub fn switch_version(repo_path: &Path, hash: &str, package_id: &str) -> Result<()> {
4457
let target_parent_path = repo_path.join("installed");
4558
let target_path = target_parent_path.join(package_id);
59+
fs::create_dir(target_parent_path)?;
4660
symlink(format!("../versions/{package_id}-{hash}"), target_path)?;
4761

62+
println!("{}", repo_path.display());
63+
4864
Ok(())
4965
}
5066

src/run/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use std::{
1010

1111
#[cfg(feature = "network")]
1212
use crate::chunks::install_tree;
13-
use crate::repo::{PackageManifest, get_package, read_manifest, versions::install_version};
13+
use crate::repo::{
14+
PackageManifest, get_package, read_manifest,
15+
versions::{install_version, switch_version},
16+
};
1417

1518
/// Starts a package from an entrypoint
1619
///
@@ -85,6 +88,8 @@ pub async fn install_package(
8588

8689
let package_manifest = get_package(&repo_manifest, package_id)
8790
.with_context(|| "Failed to get package from Repository.")?;
91+
// Don't just use an alias but actually resolve into a correct package id
92+
let package_id = &package_manifest.id;
8893

8994
// Get any chunks that are not installed
9095
#[cfg(feature = "network")]
@@ -97,7 +102,11 @@ pub async fn install_package(
97102
.await
98103
.with_context(|| "Failed to install package.")?;
99104

100-
install_version(repo_path, package_id, chunk_store_path)
105+
let hash = install_version(repo_path, package_id, chunk_store_path)?;
106+
107+
switch_version(repo_path, &hash, package_id)?;
108+
109+
Ok(())
101110
}
102111

103112
#[cfg(test)]

0 commit comments

Comments
 (0)