liteboxfs 0.2.0

A modern POSIX filesystem in a SQLite database
Documentation
/// Options for archiving files in the host filesystem to a litebox.
///
/// This is used with [`Filesystem::archive_with`].
///
/// [`Filesystem::archive_with`]: crate::Filesystem::archive_with
#[derive(Debug, Clone)]
pub struct ArchiveOptions {
    follow: bool,
    children: bool,
    recursive: bool,
    metadata: bool,
}

impl Default for ArchiveOptions {
    fn default() -> Self {
        Self::new()
    }
}

impl ArchiveOptions {
    /// Create a new [`ArchiveOptions`] default settings.
    pub fn new() -> Self {
        Self {
            follow: false,
            children: false,
            recursive: true,
            metadata: true,
        }
    }

    /// Follow symbolic links.
    ///
    /// If this is `true`, the file the symbolic links points to will be archived instead of the
    /// symbolic link itself.
    ///
    /// The default is `false`.
    pub fn follow_symlinks(mut self, follow: bool) -> Self {
        self.follow = follow;
        self
    }

    /// Archive the children of the source directory instead of the source directory itself.
    ///
    /// This puts the children of the source directory into the given destination directory.
    ///
    /// The default is `false`.
    pub fn children(mut self, children: bool) -> Self {
        self.children = children;
        self
    }

    /// Archive the source directory recursively.
    ///
    /// This has no effect if the source is a regular file.
    ///
    /// The default is `true`.
    pub fn recursive(mut self, recursive: bool) -> Self {
        self.recursive = recursive;
        self
    }

    /// Preserve file metadata when copying files into the archive.
    ///
    /// The default is `true`.
    pub fn preserve_metadata(mut self, preserve: bool) -> Self {
        self.metadata = preserve;
        self
    }
}

#[cfg(all(feature = "fs", target_family = "unix"))]
impl ArchiveOptions {
    pub(crate) fn should_follow_symlinks(&self) -> bool {
        self.follow
    }

    pub(crate) fn should_archive_children(&self) -> bool {
        self.children
    }

    pub(crate) fn is_recursive(&self) -> bool {
        self.recursive
    }

    pub(crate) fn should_preserve_metadata(&self) -> bool {
        self.metadata
    }
}

/// Options for extracting files in a litebox to host the filesystem.
///
/// This is used with [`Filesystem::extract_with`].
///
/// [`Filesystem::extract_with`]: crate::Filesystem::extract_with
#[derive(Debug, Clone)]
pub struct ExtractOptions {
    children: bool,
    recursive: bool,
}

impl Default for ExtractOptions {
    fn default() -> Self {
        Self::new()
    }
}

impl ExtractOptions {
    /// Create a new [`ExtractOptions`] with default settings.
    pub fn new() -> Self {
        Self {
            children: false,
            recursive: true,
        }
    }

    /// Extract the children of the source directory instead of the source directory itself.
    ///
    /// This puts the children of the source directory into the given destination directory.
    ///
    /// The default is `false`.
    pub fn children(mut self, children: bool) -> Self {
        self.children = children;
        self
    }

    /// Extract the source directory recursively.
    ///
    /// This has no effect if the source is a regular file.
    ///
    /// The default is `true`.
    pub fn recursive(mut self, recursive: bool) -> Self {
        self.recursive = recursive;
        self
    }
}

#[cfg(all(feature = "fs", target_family = "unix"))]
impl ExtractOptions {
    pub(crate) fn should_extract_children(&self) -> bool {
        self.children
    }

    pub(crate) fn is_recursive(&self) -> bool {
        self.recursive
    }
}