liboxen 0.53.0

Oxen is a fast data version control system, built with machine learning training data in mind. Designed to handle terabytes of data with ease, using a workflow similar to git. Version both structured and unstructured data of any modality: text, images, video, audio, CSV, Parquet, JSONL, model checkpoints, and more. liboxen is the embeddable core library behind the oxen CLI and server, which power fine tuning and inference pipelines for multimodal LLMs, image models, and video models on Oxen.ai.
use crate::constants;
use crate::error::OxenError;
use crate::model::LocalRepository;
use crate::model::MerkleHash;
use crate::util;
use std::path::PathBuf;

pub fn node_is_synced(repo: &LocalRepository, node_hash: &MerkleHash) -> bool {
    let is_synced_path = node_is_synced_file_path(repo, node_hash);
    log::debug!("Checking if node is synced: {is_synced_path:?}");
    match std::fs::read_to_string(&is_synced_path) {
        Ok(value) => {
            log::debug!("Is synced value: {value}");
            "true" == value
        }
        Err(err) => {
            log::debug!("Could not read is_synced file {is_synced_path:?}: {err}");
            false
        }
    }
}

pub fn mark_node_as_synced(
    repo: &LocalRepository,
    node_hash: &MerkleHash,
) -> Result<(), OxenError> {
    let is_synced_path = node_is_synced_file_path(repo, node_hash);
    if let Some(parent) = is_synced_path.parent() {
        log::debug!("Creating parent directory: {parent:?}");
        util::fs::create_dir_all(parent)?;
    }

    log::debug!("Writing is synced: {is_synced_path:?}");

    match std::fs::write(&is_synced_path, "true") {
        Ok(_) => {
            log::debug!("Wrote is synced file: {is_synced_path:?}");
            Ok(())
        }
        Err(err) => Err(OxenError::basic_str(format!(
            "Could not write is_synced file: {err}"
        ))),
    }
}

fn node_is_synced_file_path(repo: &LocalRepository, node_hash: &MerkleHash) -> PathBuf {
    let dir_prefix = node_hash.to_hex_hash().node_db_prefix();
    repo.path
        .join(constants::OXEN_HIDDEN_DIR)
        .join(constants::TREE_DIR)
        .join(constants::SYNC_STATUS_DIR)
        .join(constants::NODES_DIR)
        .join(dir_prefix)
        .join(constants::IS_SYNCED)
}