backup-deduplicator 0.3.0

A tool to deduplicate backups. It builds a hash tree of all files and folders in the target directory. Optionally also traversing into archives like zip or tar files. The hash tree is then used to find duplicate files and folders.
Documentation

// device id

use std::io;
use std::path::Path;
use file_id::FileId;
use serde::Serialize;

/// Device id type.
#[cfg(target_family = "unix")]
type DeviceIdType = u64;

/// Device id type.
#[cfg(target_family = "windows")]
type DeviceIdType = u64; // high-res file-id

/// File id type
#[cfg(target_family = "unix")]
type FileIdType = u64;

/// File id type
#[cfg(target_family = "windows")]
type FileIdType = u128; // high-res file-id

/// A file id handle.
/// 
/// # Fields
/// * `inode` - The inode of the file.
/// * `drive` - The device id of the file.
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct HandleIdentifier {
    pub inode: FileIdType,
    pub drive: DeviceIdType,
}

impl HandleIdentifier {
    /// Create a new handle identifier from a path.
    /// 
    /// # Arguments
    /// * `path` - The path to the file.
    /// 
    /// # Returns
    /// The handle identifier.
    /// 
    /// # Errors
    /// If the file id cannot be retrieved.
    pub fn from_path(path: impl AsRef<Path>) -> io::Result<HandleIdentifier> {
        match file_id::get_file_id(path)? {
            FileId::Inode { device_id, inode_number } => Ok(HandleIdentifier {
                // unix
                inode: inode_number as FileIdType,
                drive: device_id as DeviceIdType,
            }),
            FileId::LowRes { volume_serial_number, file_index } => Ok(HandleIdentifier {
                // windows
                inode: file_index as FileIdType,
                drive: volume_serial_number as DeviceIdType,
            }),
            FileId::HighRes { volume_serial_number, file_id } => Ok(HandleIdentifier {
                // windows
                inode: file_id as FileIdType,
                drive: volume_serial_number as DeviceIdType,
            }),
        }
    }
}