Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Add root.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Aug 20, 2023
1 parent 45d6555 commit 37603ad
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/store/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::storage_item::StorageItem;
use crate::store_error::StoreError;
use starbase_archive::Archiver;
use starbase_utils::dirs;
use starbase_utils::fs::{self, FsError};
use std::env;
use std::io;
use std::path::{Path, PathBuf};
use tracing::debug;
Expand All @@ -10,9 +12,38 @@ pub struct Store {
pub bin_dir: PathBuf,
pub cache_dir: PathBuf,
pub packages_dir: PathBuf,
pub root: PathBuf,
}

impl Store {
pub fn detect_root() -> PathBuf {
if let Ok(root) = env::var("JPM_ROOT") {
return root.into();
}

dirs::home_dir()
.expect("Could not find a home directory!")
.join(".jpm")
}

pub fn load() -> miette::Result<Self> {
let root = Self::detect_root();
let bin_dir = root.join("bin");
let cache_dir = root.join("cache");
let packages_dir = root.join("packages");

fs::create_dir_all(&bin_dir)?;
fs::create_dir_all(&cache_dir)?;
fs::create_dir_all(&packages_dir)?;

Ok(Self {
bin_dir,
cache_dir,
packages_dir,
root,
})
}

pub async fn download_archive(
&self,
url: &str,
Expand Down

0 comments on commit 37603ad

Please sign in to comment.