mod implementations;
#[cfg(test)]
mod tests;
use crate::error::*;
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Default)]
pub struct Props {
element_type: ArcDir,
hidden: bool, system: bool, device: bool, reparse: bool, compressed: bool, not_content_indexed: bool, encrypted: bool, integrity_stream: bool, virtual_file: bool, no_scrub_data: bool, extended_attributes: bool, pinned: bool, unpinned: bool, recall_on_open: bool, recall_on_data_access: bool, }
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Default)]
pub enum ArcDir {
#[default]
Directory, Archive(ArchiveProps), }
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Default)]
pub struct ArchiveProps {
read_only: bool, normal: bool, temporary: bool, sparse: bool, offline: bool, }
impl Props {
pub fn is_read_only(&self) -> Result<bool> {
match self.element_type {
ArcDir::Archive(arc_props) => Ok(arc_props.read_only),
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile(
"The read_only property is exclusive for files".to_string(),
),
}),
}
}
pub fn read_only(&mut self, read_only: bool) -> Result<()> {
match self.element_type {
ArcDir::Archive(mut arc_props) => {
arc_props.read_only = read_only;
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
Ok(())
}
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile(
"The read_only property is exclusive for files".to_string(),
),
}),
}
}
pub fn is_hidden(&self) -> bool {
self.hidden
}
pub fn hidden(&mut self, hidden: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if hidden {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.hidden = hidden;
}
pub fn is_system(&self) -> bool {
self.system
}
fn _system(&mut self, system: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if system {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.system = system;
}
pub fn is_archive(&self) -> bool {
match self.element_type {
ArcDir::Archive(_) => true,
ArcDir::Directory => false,
}
}
pub fn is_directory(&self) -> bool {
match self.element_type {
ArcDir::Directory => true,
ArcDir::Archive(_) => false,
}
}
pub fn change_element_type(&mut self, element_type: ArcDir) {
self.element_type = element_type;
}
pub fn is_device(&self) -> bool {
self.device
}
fn _device(&mut self, device: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if device {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.device = device;
}
pub fn is_normal(&self) -> Result<bool> {
match self.element_type {
ArcDir::Archive(arc_props) => Ok(arc_props.normal),
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The normal property is exclusive for files".to_string()),
}),
}
}
pub fn normal(&mut self, normal: bool) -> Result<()> {
let comp_arc_props = ArchiveProps {
normal: true,
..Default::default()
};
let comp_arc_props_2 = ArchiveProps::default();
match self.element_type {
ArcDir::Archive(mut arc_props) => {
if arc_props == comp_arc_props || arc_props == comp_arc_props_2 {
arc_props.normal = normal;
self.element_type = ArcDir::Archive(arc_props);
} else {
return Err(Error { kind: ErrorKind::Other("The normal file property must be only applied in a file with only itself set to true".to_string()) });
}
Ok(())
}
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The normal property is exclusive for files".to_string()),
}),
}
}
pub fn is_temporary(&self) -> Result<bool> {
match self.element_type {
ArcDir::Archive(arc_props) => Ok(arc_props.temporary),
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile(
"The temporary property is exclusive for files".to_string(),
),
}),
}
}
pub fn temporary(&mut self, temporary: bool) -> Result<()> {
match self.element_type {
ArcDir::Archive(mut arc_props) => {
arc_props.temporary = temporary;
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
Ok(())
}
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile(
"The temporary property is exclusive for files".to_string(),
),
}),
}
}
pub fn is_sparse(&self) -> Result<bool> {
match self.element_type {
ArcDir::Archive(arc_props) => Ok(arc_props.sparse),
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The sparse property is exclusive for files".to_string()),
}),
}
}
pub fn sparse(&mut self, sparse: bool) -> Result<()> {
match self.element_type {
ArcDir::Archive(mut arc_props) => {
arc_props.sparse = sparse;
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
Ok(())
}
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The sparse property is exclusive for files".to_string()),
}),
}
}
pub fn is_reparse(&self) -> bool {
self.reparse
}
pub fn reparse(&mut self, reparse: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if reparse {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.reparse = reparse;
}
pub fn is_compressed(&self) -> bool {
self.compressed
}
pub fn compressed(&mut self, compressed: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if compressed {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.compressed = compressed;
}
pub fn is_offline(&self) -> Result<bool> {
match self.element_type {
ArcDir::Archive(arc_props) => Ok(arc_props.offline),
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The offline property is exclusive to files".to_string()),
}),
}
}
pub fn offline(&mut self, offline: bool) -> Result<()> {
match self.element_type {
ArcDir::Archive(mut arc_props) => {
arc_props.offline = offline;
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
Ok(())
}
ArcDir::Directory => Err(Error {
kind: ErrorKind::NotAFile("The offline property is exclusive to files".to_string()),
}),
}
}
pub fn is_not_content_indexed(&self) -> bool {
self.not_content_indexed
}
pub fn not_content_indexed(&mut self, not_content_indexed: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if not_content_indexed {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.not_content_indexed = not_content_indexed;
}
pub fn is_encrypted(&self) -> bool {
self.encrypted
}
pub fn encrypted(&mut self, encrypted: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if encrypted {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.encrypted = encrypted;
}
pub fn is_integrity_stream(&self) -> bool {
self.integrity_stream
}
pub fn integrity_stream(&mut self, integrity_stream: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if integrity_stream {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.integrity_stream = integrity_stream;
}
pub fn is_virtual_file(&self) -> bool {
self.virtual_file
}
fn _virtual_file(&mut self, virtual_file: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if virtual_file {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.virtual_file = virtual_file;
}
pub fn is_no_scrub_data(&self) -> bool {
self.no_scrub_data
}
pub fn no_scrub_data(&mut self, no_scrub_data: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if no_scrub_data {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.no_scrub_data = no_scrub_data;
}
pub fn is_extended_attributes(&self) -> bool {
self.extended_attributes
}
fn _extended_attributes(&mut self, extended_attributes: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if extended_attributes {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.extended_attributes = extended_attributes;
}
pub fn is_pinned(&self) -> bool {
self.pinned
}
pub fn pinned(&mut self, pinned: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if pinned {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.pinned = pinned;
}
pub fn is_unpinned(&self) -> bool {
self.unpinned
}
pub fn unpinned(&mut self, unpinned: bool) {
self.unpinned = unpinned;
}
pub fn is_recall_on_open(&self) -> bool {
self.recall_on_open
}
pub fn recall_on_open(&mut self, recall_on_open: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if recall_on_open {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.recall_on_open = recall_on_open;
}
pub fn is_recall_on_data_access(&self) -> bool {
self.recall_on_data_access
}
pub fn recall_on_data_access(&mut self, recall_on_data_access: bool) {
if let ArcDir::Archive(mut arc_props) = self.element_type {
if recall_on_data_access {
arc_props.normal = false;
self.element_type = ArcDir::Archive(arc_props);
}
}
self.recall_on_data_access = recall_on_data_access;
}
}