Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor vendor dir #13

Merged
merged 8 commits into from
Aug 17, 2023
Merged
Changes from 1 commit
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
Next Next commit
Refactor package installation / vendor dir setup
  • Loading branch information
mara-schulke committed Aug 16, 2023
commit ea480f36b89f6bde35ae4acf9f9d8f5076f18282
29 changes: 21 additions & 8 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl PackageStore {
}

/// Unpacks a package into a local directory
pub async fn unpack(package: &Package, path: &Path) -> eyre::Result<()> {
pub async fn unpack(package: &Package) -> eyre::Result<()> {
let mut tar = Vec::new();

let mut gz = flate2::read::GzDecoder::new(package.tgz.clone().reader());
Expand All @@ -61,7 +61,7 @@ impl PackageStore {

let mut tar = tar::Archive::new(Bytes::from(tar).reader());

let pkg_dir = path.join(package.manifest.name.as_str());
let pkg_dir = Path::new(Self::PROTO_VENDOR_PATH).join(package.manifest.name.as_str());

fs::remove_dir_all(&pkg_dir).await.ok();

Expand All @@ -86,9 +86,7 @@ impl PackageStore {
pub async fn install<R: Registry>(dependency: Dependency, registry: R) -> eyre::Result<()> {
let package = registry.download(dependency).await?;

let vendor_dir = Path::new(Self::PROTO_VENDOR_PATH);

Self::unpack(&package, vendor_dir).await?;
Self::unpack(&package).await?;

let mut tree = format!(
":: installed {}@{}",
Expand All @@ -97,14 +95,29 @@ impl PackageStore {

let Manifest { dependencies, .. } = Self::resolve(&package.manifest.name).await?;

let package_dir = &vendor_dir.join(package.manifest.name.as_str());

let dependency_count = dependencies.len();

for (index, dependency) in dependencies.into_iter().enumerate() {
if let Ok(manifest) = Self::resolve(&dependency.package).await {
let existing = manifest.package.wrap_err(eyre::eyre!(
"Found installed manifest for {} but it is malformed",
dependency.package,
))?;

eyre::ensure!(
existing.version == dependency.manifest.version,
"Another dependency in your project requires {}@{} which colides with {}@{} required by {}",
mara-schulke marked this conversation as resolved.
Show resolved Hide resolved
existing.name,
existing.version,
dependency.package,
dependency.manifest.version,
package.manifest.name,
);
}

let dependency = registry.download(dependency).await?;

Self::unpack(&dependency, package_dir).await?;
Self::unpack(&dependency).await?;

let tree_char = if index + 1 == dependency_count {
'┗'
Expand Down