vdsl-sync 0.6.0

File synchronization engine — N-location, pluggable store & backend
Documentation
//! TopologyFileStore — TopologyFile永続化トレイト。
//!
//! TopologyFile(ファイル身元 / inode)のCRUD + ハッシュ検索。

use async_trait::async_trait;

use crate::domain::file_type::FileType;
use crate::domain::topology_file::TopologyFile;
use crate::infra::error::InfraError;

/// TopologyFile永続化。
///
/// Topology上のファイル身元情報(canonical_hash, relative_path, file_type等)を管理する。
/// LocationFile(各Locationでの実体情報)は [`LocationFileStore`] が管理する。
#[async_trait]
pub trait TopologyFileStore: Send + Sync {
    /// TopologyFileを保存(新規 or 更新)。
    ///
    /// idが既存の場合はUPDATE、なければINSERT。
    async fn upsert(&self, file: &TopologyFile) -> Result<(), InfraError>;

    /// IDでTopologyFileを取得。
    async fn get_by_id(&self, id: &str) -> Result<Option<TopologyFile>, InfraError>;

    /// relative_pathでTopologyFileを取得(deleted除外)。
    async fn get_by_path(&self, relative_path: &str) -> Result<Option<TopologyFile>, InfraError>;

    /// canonical_hashでTopologyFileを検索(deleted除外)。
    ///
    /// rename検出で使用: スキャン結果のcontent_hashがTopologyFileのcanonical_hashに一致
    /// すれば同一Entity。
    async fn find_by_canonical_hash(&self, hash: &str) -> Result<Option<TopologyFile>, InfraError>;

    /// 生存中(deleted_at IS NULL)のTopologyFile一覧。
    async fn list_active(
        &self,
        file_type: Option<FileType>,
        limit: Option<usize>,
    ) -> Result<Vec<TopologyFile>, InfraError>;

    /// 削除済み(deleted_at IS NOT NULL)のTopologyFile一覧。
    ///
    /// distribute_delete_actions()で使用: 削除済みファイルのLocationFileを掃除する。
    async fn list_deleted(&self) -> Result<Vec<TopologyFile>, InfraError>;

    /// 削除済みTFを物理削除。
    ///
    /// 全LocationFileのdelete transferが完了し、LFが0件になった後に呼ぶ。
    /// B2 archived データは独立して残るため、restore_from_archiveで復元可能。
    async fn hard_delete(&self, id: &str) -> Result<bool, InfraError>;

    /// 生存中ファイル数。
    async fn count_active(&self) -> Result<usize, InfraError>;

    /// 全TopologyFileのrelative_path一覧(deleted除外)。
    ///
    /// スキャン結果との差分でVanished検出に使用。
    async fn list_active_paths(&self) -> Result<Vec<String>, InfraError>;
}