Struct Relations

Source
pub struct Relations {
    pub files: HashMap<PathBuf, SingleFile>,
}
Expand description

Relations is a struct that stores all information about rif

Fields§

§files: HashMap<PathBuf, SingleFile>

Implementations§

Source§

impl Relations

Source

pub fn new() -> Self

Source

pub fn display_file(&self, path: &Path) -> String

Display a single file as human readable form

§Args
  • path - A file path(name) to display
§Display format

> <FILE_NAME> | [REFS]

Source

pub fn display_stale_files(&self, depth: usize) -> Result<(), RifError>

Only display stale files

Source

pub fn display_file_depth( &self, path: &Path, depth: usize, ) -> Result<(), RifError>

Print a single file’s relation

§Args
  • path - File name to print
  • depth - Desired depth value to display
Source

pub fn display_depth(&self, depth: usize) -> Result<(), RifError>

Print rif relation tree with given nested level

§Args
  • depth - Desired depth value to display
Source

pub fn add_file(&mut self, file_path: &Path) -> Result<bool, RifError>

Add file to rif list

Fails when path doesn’t exist. Sanity is checked after addition.

§Args
  • file_path - A file path to add
Source

pub fn remove_file(&mut self, file_path: &Path) -> Result<bool, RifError>

Remove file from rif

Path validity doesn’t matter.

§Args
  • file_path - File path(name) to remove from rif.
Source

pub fn rename_file( &mut self, file_path: &Path, new_name: &Path, ) -> Result<(), RifError>

Rename a file in rif

This operation require new_name path does exists and doesn’t check path of old_name

§Args
  • file_path - File path(name) to rename.
  • new_name - New file name to apply
Source

pub fn update_filestamp(&mut self, file_path: &Path) -> Result<(), RifError>

Update filestamp of file

Update file’s timestamp and last modified time into file’s system last modified time.

§Args
  • file_path - File path(name) to update timestamp
Source

pub fn update_filestamp_force( &mut self, file_path: &Path, ) -> Result<(), RifError>

Forcefully update filestamp of file

Update file’s timestamp into current unix time.

§Args
  • file_path - File path(name) to update timestamp
Source

pub fn discard_change(&mut self, file_path: &Path) -> Result<(), RifError>

Discard file modification

Retain file’s timestamp and only update last modified time.

§Args
  • file_path - File path(name) to discard modification
Source

pub fn add_reference( &mut self, file_path: &Path, ref_files: &HashSet<PathBuf>, ) -> Result<(), RifError>

Set references to a file

This is union operation thus existing files are not affected. References should be existent in rif list to be added to a file.

§Args
  • file_path - File path(name) to add references
  • ref_files - File pahts to set as references
Source

pub fn remove_reference( &mut self, file_path: &Path, ref_files: &HashSet<PathBuf>, ) -> Result<(), RifError>

Unset references from a file

This is minus operation thus references don’t have to be valid path.

§Args
  • file_path - File path(name) to discard modification
  • ref_files - File pahts to unset as references
Source

pub fn set_file_status( &mut self, file_path: &Path, file_status: FileStatus, ) -> Result<(), RifError>

Set status for a file

§Args
  • file_path - File path(name) to set a status
  • file_status - File status to set for the file
Source

pub fn sanity_check(&self) -> Result<(), RifError>

Check sanity of rif list

Sanity is assured when: file is not referencing itself, file referencing conclues to infinite loop

Source

pub fn sanity_fix(&mut self) -> Result<(), RifError>

Fix invalid format so that sanity can be retained.

Repeatedly find invalid referecning and fix until sanity check succeeds.

Source

pub fn track_modified_files<'a>( &'a self, to_be_added_later: impl IntoIterator<Item = &'a PathBuf> + 'a, ) -> Result<(), RifError>

Track and print modified files

Modfication is determined by comparing rif’s last modified and system’s modifid time. If rif’s last modified time is oldere than system’s modified time, it is considered as modified.

Source

pub fn get_deleted_files(&self) -> HashSet<PathBuf>

Source

pub fn get_modified_files(&self) -> Result<Vec<PathBuf>, RifError>

Get list of modified files

Logic is very similar to track_modified_files but it returns list of modified files.

Source

pub fn track_unregistered_files( &self, black_list: &HashSet<PathBuf>, to_be_registerd: &HashSet<PathBuf>, ) -> Result<(), RifError>

Track and display unregistered files

Unregistered file is a file which exists in under directory where rif file resides.

§Args
  • black_list - Blacklists to to ignore when tracking unregistered files
Source

pub fn find_depends(&self, target_path: &Path) -> Result<Vec<PathBuf>, RifError>

Source

pub fn read_from_file( path: Option<impl AsRef<Path>>, ) -> Result<Relations, RifError>

Read rif file and return rif list

Source

pub fn read_as_raw( path: Option<impl AsRef<Path>>, ) -> Result<Relations, RifError>

Read rif file without sanity check

Source

pub fn save_to_file( &self, path: Option<impl AsRef<Path>>, ) -> Result<(), RifError>

Save rif list into rif file

Trait Implementations§

Source§

impl Debug for Relations

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Relations

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Relations

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Relations

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,