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

Clone pantry to same location as pkgx^1 #1125

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ jobs:
- run: |
set -x
rm -rf ~/.pkgx
rm -rf ~/.cache/pkgx/pantry/projects/git-scm.org
rm -rf ~/.local/share/pkgx/pantry/projects/git-scm.org
rm ~/.cache/pkgx/pantry.2.db
pkgx curl --version
test -f ~/.cache/pkgx/pantry.2.db
test ! -d ~/.cache/pkgx/pantry/projects/git-scm.org
test ! -d ~/.local/share/pkgx/pantry/projects/git-scm.org
pkgx git --version
test -d ~/.cache/pkgx/pantry/projects/git-scm.org
test -d ~/.local/share/pkgx/pantry/projects/git-scm.org
if: ${{ matrix.os == 'ubuntu-latest' }}
# ^^ only on one platform as wasteful otherwise

Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pkgx"
description = "Run anything"
authors = ["Max Howell <[email protected]>", "Jacob Heider <[email protected]>"]
license = "Apache-2.0"
version = "2.2.1"
version = "2.2.2"
edition = "2021"
repository = "https://github.com/pkgxdev/pkgx"

Expand All @@ -14,7 +14,7 @@ regex = "1.11.1"
indicatif = "0.17.9"
nix = { version = "0.29.0", features = ["process"] }
serde_json = "1.0.135"
libpkgx = { version = "0.3.1", path = "../lib" }
libpkgx = { version = "0.3.2", path = "../lib" }
console = { version = "0.15", default-features = false, features = [
"ansi-parsing",
] }
Expand Down
5 changes: 2 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

let config = Config::new()?;

let cache_dir = config.pantry_dir.parent().unwrap();
std::fs::create_dir_all(cache_dir)?;
let mut conn = Connection::open(cache_dir.join("pantry.2.db"))?;
std::fs::create_dir_all(config.pantry_db_file.parent().unwrap())?;
let mut conn = Connection::open(&config.pantry_db_file)?;

let spinner = if flags.silent || flags.quiet {
None
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libpkgx"
description = "Install and run `pkgx` packages"
authors = ["Max Howell <[email protected]>", "Jacob Heider <[email protected]>"]
license = "Apache-2.0"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
repository = "https://github.com/pkgxdev/pkgx"

Expand Down
43 changes: 38 additions & 5 deletions crates/lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ use std::path::PathBuf;
#[derive(Debug)]
pub struct Config {
pub pantry_dir: PathBuf,
pub pantry_db_file: PathBuf,
pub dist_url: String,
pub pkgx_dir: PathBuf,
}

impl Config {
pub fn new() -> io::Result<Self> {
let pantry_dir = get_pantry_dir()?;
let pantry_db_file: PathBuf = get_pantry_db_file()?;
let dist_url = get_dist_url();
let pkgx_dir = get_pkgx_dir()?;
Ok(Self {
pantry_dir,
pantry_db_file,
dist_url,
pkgx_dir,
})
Expand All @@ -29,16 +32,33 @@ fn get_dist_url() -> String {
env!("PKGX_DIST_URL").to_string()
}

fn get_pantry_dir() -> io::Result<PathBuf> {
#[allow(non_snake_case)]
fn get_PKGX_PANTRY_DIR() -> Option<PathBuf> {
if let Ok(env_dir) = env::var("PKGX_PANTRY_DIR") {
let path = PathBuf::from(env_dir);
if !path.is_absolute() {
return Ok(env::current_dir()?.join(path));
if path.is_absolute() {
Some(path)
} else if let Ok(cwd) = env::current_dir() {
Some(cwd.join(path))
} else {
return Ok(path);
None
}
} else {
None
}
}

fn get_pantry_dir() -> io::Result<PathBuf> {
if let Some(path) = get_PKGX_PANTRY_DIR() {
Ok(path)
} else if let Some(path) = dirs_next::data_local_dir() {
Ok(path.join("pkgx/pantry"))
} else {
Err(io::Error::new(
io::ErrorKind::NotFound,
"Could not determine cache directory",
))
}
Ok(dirs_next::cache_dir().unwrap().join("pkgx/pantry"))
}

fn get_pkgx_dir() -> io::Result<PathBuf> {
Expand All @@ -59,3 +79,16 @@ fn get_pkgx_dir() -> io::Result<PathBuf> {
Ok(default.unwrap())
}
}

fn get_pantry_db_file() -> io::Result<PathBuf> {
if let Some(path) = get_PKGX_PANTRY_DIR() {
Ok(path.join("pantry.2.db"))
} else if let Some(path) = dirs_next::cache_dir() {
Ok(path.join("pkgx/pantry.2.db"))
} else {
Err(io::Error::new(
io::ErrorKind::NotFound,
"Could not determine data directory",
))
}
}
5 changes: 2 additions & 3 deletions crates/lib/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ pub fn should(config: &Config) -> Result<bool, Box<dyn Error>> {
if !config.pantry_dir.join("projects").is_dir() {
Ok(true)
} else {
let path = config.pantry_dir.parent().unwrap().join("pantry.2.db");
// the file always exists because we create the connection
// but will be 0 bytes if we need to fill it
Ok(std::fs::metadata(&path)?.len() == 0)
Ok(std::fs::metadata(&config.pantry_db_file)?.len() == 0)
}
}

Expand Down Expand Up @@ -51,7 +50,7 @@ async fn replace(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn E
let url = env!("PKGX_PANTRY_TARBALL_URL");
let dest = &config.pantry_dir;

std::fs::create_dir_all(dest.clone())?;
std::fs::create_dir_all(dest)?;
let dir = OpenOptions::new()
.read(true) // Open in read-only mode; no need to write.
.open(dest)?;
Expand Down
Loading