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

If PKGX_PANTRY_DIR is set, don’t blow it away #1121

Merged
merged 1 commit into from
Feb 11, 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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ jobs:
exit 1
fi

# check that we update the pantry for unknown programs
# this works by deleting the entry for git then forcing
# pkgx to update the db, then trying to get git again
- run: |
set -x
rm -rf ~/.pkgx
rm -rf ~/.cache/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
pkgx git --version
test -d ~/.cache/pkgx/pantry/projects/git-scm.org
if: ${{ matrix.os == 'ubuntu-latest' }}
# ^^ only on one platform as wasteful otherwise

- name: generate coverage
run: |
cargo install rustfilt
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
if let Some(spinner) = &spinner {
spinner.set_message("syncing pkg-db…");
}
sync::replace(&config, &mut conn).await?;
sync::ensure(&config, &mut conn).await?;
true
} else {
false
Expand Down Expand Up @@ -112,7 +112,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
spinner.set_message(msg);
}
// cmd not found ∴ sync in case it is new
sync::replace(&config, &mut conn).await?;
sync::update(&config, &mut conn).await?;
if let Some(spinner) = &spinner {
spinner.set_message("resolving pkg graph…");
}
Expand Down
30 changes: 29 additions & 1 deletion crates/lib/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,35 @@ pub fn should(config: &Config) -> Result<bool, Box<dyn Error>> {
}
}

pub async fn replace(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> {
// doesn’t replace pantry clone, will build db
// essential for working in a local pantry clone with PKGX_PANTRY_DIR set
pub async fn ensure(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> {
if !config.pantry_dir.join("projects").is_dir() {
replace(config, conn).await
} else {
let dest = &config.pantry_dir;
std::fs::create_dir_all(dest.clone())?;
let dir = OpenOptions::new()
.read(true) // Open in read-only mode; no need to write.
.open(dest)?;
dir.lock_exclusive()?;

pantry_db::cache(config, conn)?;

FileExt::unlock(&dir)?;

Ok(())
}
}

pub async fn update(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> {
if std::env::var("PKGX_PANTRY_DIR").is_ok() {
return Err("PKGX_PANTRY_DIR is set, refusing to update pantry")?;
}
replace(config, conn).await
}

async fn replace(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> {
let url = env!("PKGX_PANTRY_TARBALL_URL");
let dest = &config.pantry_dir;

Expand Down