Skip to content

Commit c2ebbc1

Browse files
committed
Clone pantry to same location as pkgx^1
This change was thoughtless and accidental. It means we can end up with pkgx^1 and pkgx^2 getting out of sync.
1 parent 719359a commit c2ebbc1

File tree

7 files changed

+54
-23
lines changed

7 files changed

+54
-23
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ jobs:
133133
- run: |
134134
set -x
135135
rm -rf ~/.pkgx
136-
rm -rf ~/.cache/pkgx/pantry/projects/git-scm.org
136+
rm -rf ~/.local/share/pkgx/pantry/projects/git-scm.org
137137
rm ~/.cache/pkgx/pantry.2.db
138138
pkgx curl --version
139139
test -f ~/.cache/pkgx/pantry.2.db
140-
test ! -d ~/.cache/pkgx/pantry/projects/git-scm.org
140+
test ! -d ~/.local/share/pkgx/pantry/projects/git-scm.org
141141
pkgx git --version
142-
test -d ~/.cache/pkgx/pantry/projects/git-scm.org
142+
test -d ~/.local/share/pkgx/pantry/projects/git-scm.org
143143
if: ${{ matrix.os == 'ubuntu-latest' }}
144144
# ^^ only on one platform as wasteful otherwise
145145

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "pkgx"
33
description = "Run anything"
44
authors = ["Max Howell <mxcl@me.com>", "Jacob Heider <jacob@pkgx.dev>"]
55
license = "Apache-2.0"
6-
version = "2.2.1"
6+
version = "2.2.2"
77
edition = "2021"
88
repository = "https://github.com/pkgxdev/pkgx"
99

@@ -14,7 +14,7 @@ regex = "1.11.1"
1414
indicatif = "0.17.9"
1515
nix = { version = "0.29.0", features = ["process"] }
1616
serde_json = "1.0.135"
17-
libpkgx = { version = "0.3.1", path = "../lib" }
17+
libpkgx = { version = "0.3.2", path = "../lib" }
1818
console = { version = "0.15", default-features = false, features = [
1919
"ansi-parsing",
2020
] }

crates/cli/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
4444

4545
let config = Config::new()?;
4646

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

5150
let spinner = if flags.silent || flags.quiet {
5251
None

crates/lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libpkgx"
33
description = "Install and run `pkgx` packages"
44
authors = ["Max Howell <mxcl@me.com>", "Jacob Heider <jacob@pkgx.dev>"]
55
license = "Apache-2.0"
6-
version = "0.3.1"
6+
version = "0.3.2"
77
edition = "2021"
88
repository = "https://github.com/pkgxdev/pkgx"
99

crates/lib/src/config.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ use std::path::PathBuf;
55
#[derive(Debug)]
66
pub struct Config {
77
pub pantry_dir: PathBuf,
8+
pub pantry_db_file: PathBuf,
89
pub dist_url: String,
910
pub pkgx_dir: PathBuf,
1011
}
1112

1213
impl Config {
1314
pub fn new() -> io::Result<Self> {
1415
let pantry_dir = get_pantry_dir()?;
16+
let pantry_db_file: PathBuf = get_pantry_db_file()?;
1517
let dist_url = get_dist_url();
1618
let pkgx_dir = get_pkgx_dir()?;
1719
Ok(Self {
1820
pantry_dir,
21+
pantry_db_file,
1922
dist_url,
2023
pkgx_dir,
2124
})
@@ -29,16 +32,33 @@ fn get_dist_url() -> String {
2932
env!("PKGX_DIST_URL").to_string()
3033
}
3134

32-
fn get_pantry_dir() -> io::Result<PathBuf> {
35+
#[allow(non_snake_case)]
36+
fn get_PKGX_PANTRY_DIR() -> Option<PathBuf> {
3337
if let Ok(env_dir) = env::var("PKGX_PANTRY_DIR") {
3438
let path = PathBuf::from(env_dir);
35-
if !path.is_absolute() {
36-
return Ok(env::current_dir()?.join(path));
39+
if path.is_absolute() {
40+
Some(path)
41+
} else if let Ok(cwd) = env::current_dir() {
42+
Some(cwd.join(path))
3743
} else {
38-
return Ok(path);
44+
None
3945
}
46+
} else {
47+
None
48+
}
49+
}
50+
51+
fn get_pantry_dir() -> io::Result<PathBuf> {
52+
if let Some(path) = get_PKGX_PANTRY_DIR() {
53+
Ok(path)
54+
} else if let Some(path) = dirs_next::data_local_dir() {
55+
Ok(path.join("pkgx/pantry"))
56+
} else {
57+
Err(io::Error::new(
58+
io::ErrorKind::NotFound,
59+
"Could not determine cache directory",
60+
))
4061
}
41-
Ok(dirs_next::cache_dir().unwrap().join("pkgx/pantry"))
4262
}
4363

4464
fn get_pkgx_dir() -> io::Result<PathBuf> {
@@ -59,3 +79,16 @@ fn get_pkgx_dir() -> io::Result<PathBuf> {
5979
Ok(default.unwrap())
6080
}
6181
}
82+
83+
fn get_pantry_db_file() -> io::Result<PathBuf> {
84+
if let Some(path) = get_PKGX_PANTRY_DIR() {
85+
Ok(path.join("pantry.2.db"))
86+
} else if let Some(path) = dirs_next::cache_dir() {
87+
Ok(path.join("pkgx/pantry.2.db"))
88+
} else {
89+
Err(io::Error::new(
90+
io::ErrorKind::NotFound,
91+
"Could not determine data directory",
92+
))
93+
}
94+
}

crates/lib/src/sync.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ pub fn should(config: &Config) -> Result<bool, Box<dyn Error>> {
1212
if !config.pantry_dir.join("projects").is_dir() {
1313
Ok(true)
1414
} else {
15-
let path = config.pantry_dir.parent().unwrap().join("pantry.2.db");
1615
// the file always exists because we create the connection
1716
// but will be 0 bytes if we need to fill it
18-
Ok(std::fs::metadata(&path)?.len() == 0)
17+
Ok(std::fs::metadata(&config.pantry_db_file)?.len() == 0)
1918
}
2019
}
2120

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

54-
std::fs::create_dir_all(dest.clone())?;
53+
std::fs::create_dir_all(dest)?;
5554
let dir = OpenOptions::new()
5655
.read(true) // Open in read-only mode; no need to write.
5756
.open(dest)?;

0 commit comments

Comments
 (0)