githttp-fs 1.15.4

A git-backed content management database served over HTTP
// githttp-fs
//
// Git-based Content Management System
// Copyright: 2026, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

//! What the per-directory index files githttp-fs keeps inside a tenant
//! repository have in common: the file-order index (`order.rs`) and the
//! file-dates index (`dates.rs`).
//!
//! Both are stored one per directory, keyed by the leaf names of that
//! directory's entries, at a reserved leaf name. Neither is content, so every
//! `/files` route treats a reserved name as if nothing were there — whatever
//! `include_hidden_files` says. The routines both need live here, so the two
//! modules hold only what is specific to each: its name, its format, its
//! rules.

use crate::{dates, order};

/// Splits a repo-root-relative path into its parent directory and its leaf
/// name. A path with no slash sits at the repository root, so its parent is
/// the empty string.
pub fn split_parent(path: &str) -> (&str, &str) {
    match path.rsplit_once('/') {
        Some((parent, leaf)) => (parent, leaf),
        None => ("", path),
    }
}

/// Repo-root-relative path of the index named `file_name` for `directory`
/// (`""` being the repository root).
pub fn index_file_path(directory: &str, file_name: &str) -> String {
    if directory.is_empty() {
        file_name.to_string()
    } else {
        format!("{}/{}", directory, file_name)
    }
}

/// Whether a leaf name is one of the index files githttp-fs reserves.
pub fn is_reserved_name(name: &str) -> bool {
    name == order::ORDER_FILE_NAME || name == dates::DATES_FILE_NAME
}

/// [`is_reserved_name`] for a repo-root-relative path, compared on its leaf
/// name so it holds at any depth.
pub fn is_reserved_file(path: &str) -> bool {
    is_reserved_name(split_parent(path).1)
}