rclean-cli 0.2.0

Find and safely clean rebuildable developer artifacts across local workspaces
//! Recoverable soft-delete layer ("graveyard") for cleaned candidates.
//!
//! Architecture lives in `docs/specs/v0.1.x-roadmap.md` §4.7. This
//! module is the storage half: it can move a candidate directory to
//! the graveyard, append a manifest record, list active graves, and
//! restore one. CLI wiring (`clean --graveyard`, `rclean restore`,
//! `rclean graveyard list/gc`) lands in follow-up PRs.
//!
//! Everything here is feature-gated behind `graveyard` so a
//! `cargo install rclean-cli --no-default-features` install strips
//! the module entirely.
//!
//! `dead_code` + `unused_imports` are intentionally allowed at the
//! module level for the same reason — the public API surface is
//! reviewed in isolation here, then exercised by the follow-up CLI
//! integration PR. Inner-module tests (`#[cfg(test)] mod tests`)
//! exercise every public item so it doesn't drift from the spec
//! while waiting for CLI wiring.

#![allow(dead_code, unused_imports)]

mod error;
mod id;
mod manifest;
mod store;

pub use error::GraveyardError;
pub use manifest::{GraveId, ManifestReader, ManifestRecord, RecordWriter};
pub use store::{Grave, GraveInput, Graveyard};

use std::path::PathBuf;

/// Default graveyard root per platform (SPEC §4.7.1).
///
///   Linux/macOS: `$XDG_DATA_HOME/rclean/graveyard/` or
///                `$HOME/.local/share/rclean/graveyard/`
///   Windows:     `%LOCALAPPDATA%\rclean\graveyard\` or
///                `%USERPROFILE%\AppData\Local\rclean\graveyard\`
///
/// Last-resort fallback to `./.rclean-graveyard` only when none of
/// the home env vars are set — mainly for CI sandboxes with
/// stripped environments.
pub fn default_root() -> PathBuf {
    if let Ok(xdg) = std::env::var("XDG_DATA_HOME")
        && !xdg.is_empty()
    {
        return PathBuf::from(xdg).join("rclean").join("graveyard");
    }
    if let Ok(localapp) = std::env::var("LOCALAPPDATA")
        && !localapp.is_empty()
    {
        return PathBuf::from(localapp).join("rclean").join("graveyard");
    }
    if let Ok(home) = std::env::var("HOME")
        && !home.is_empty()
    {
        return PathBuf::from(home)
            .join(".local")
            .join("share")
            .join("rclean")
            .join("graveyard");
    }
    if let Ok(profile) = std::env::var("USERPROFILE")
        && !profile.is_empty()
    {
        return PathBuf::from(profile)
            .join("AppData")
            .join("Local")
            .join("rclean")
            .join("graveyard");
    }
    PathBuf::from(".rclean-graveyard")
}