zoi/project/
lockfile.rs

1use crate::pkg::types;
2use anyhow::Result;
3use std::collections::HashMap;
4use std::fs;
5
6fn get_lockfile_path() -> Result<std::path::PathBuf> {
7    Ok(std::env::current_dir()?.join("zoi.lock"))
8}
9
10pub fn read_zoi_lock() -> Result<types::ZoiLock> {
11    let path = get_lockfile_path()?;
12    if !path.exists() {
13        return Ok(types::ZoiLock {
14            packages: HashMap::new(),
15        });
16    }
17    let content = fs::read_to_string(path)?;
18    let lockfile = serde_json::from_str(&content)?;
19    Ok(lockfile)
20}
21
22pub fn write_zoi_lock(lockfile: &types::ZoiLock) -> Result<()> {
23    let path = get_lockfile_path()?;
24    let content = serde_json::to_string_pretty(lockfile)?;
25    fs::write(path, content)?;
26    Ok(())
27}