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
impl Relations
pub fn new() -> Self
Sourcepub fn display_file(&self, path: &Path) -> String
pub fn display_file(&self, path: &Path) -> String
Sourcepub fn display_stale_files(&self, depth: usize) -> Result<(), RifError>
pub fn display_stale_files(&self, depth: usize) -> Result<(), RifError>
Only display stale files
Sourcepub fn display_file_depth(
&self,
path: &Path,
depth: usize,
) -> Result<(), RifError>
pub fn display_file_depth( &self, path: &Path, depth: usize, ) -> Result<(), RifError>
Print a single file’s relation
§Args
path
- File name to printdepth
- Desired depth value to display
Sourcepub fn add_file(&mut self, file_path: &Path) -> Result<bool, RifError>
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
Sourcepub fn remove_file(&mut self, file_path: &Path) -> Result<bool, RifError>
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.
Sourcepub fn rename_file(
&mut self,
file_path: &Path,
new_name: &Path,
) -> Result<(), RifError>
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
Sourcepub fn update_filestamp(&mut self, file_path: &Path) -> Result<(), RifError>
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
Sourcepub fn update_filestamp_force(
&mut self,
file_path: &Path,
) -> Result<(), RifError>
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
Sourcepub fn discard_change(&mut self, file_path: &Path) -> Result<(), RifError>
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
Sourcepub fn add_reference(
&mut self,
file_path: &Path,
ref_files: &HashSet<PathBuf>,
) -> Result<(), RifError>
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 referencesref_files
- File pahts to set as references
Sourcepub fn remove_reference(
&mut self,
file_path: &Path,
ref_files: &HashSet<PathBuf>,
) -> Result<(), RifError>
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 modificationref_files
- File pahts to unset as references
Sourcepub fn set_file_status(
&mut self,
file_path: &Path,
file_status: FileStatus,
) -> Result<(), RifError>
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 statusfile_status
- File status to set for the file
Sourcepub fn sanity_check(&self) -> Result<(), RifError>
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
Sourcepub fn sanity_fix(&mut self) -> Result<(), RifError>
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.
Sourcepub fn track_modified_files<'a>(
&'a self,
to_be_added_later: impl IntoIterator<Item = &'a PathBuf> + 'a,
) -> Result<(), RifError>
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.
pub fn get_deleted_files(&self) -> HashSet<PathBuf>
Sourcepub fn get_modified_files(&self) -> Result<Vec<PathBuf>, RifError>
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.
Sourcepub fn track_unregistered_files(
&self,
black_list: &HashSet<PathBuf>,
to_be_registerd: &HashSet<PathBuf>,
) -> Result<(), RifError>
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
pub fn find_depends(&self, target_path: &Path) -> Result<Vec<PathBuf>, RifError>
Sourcepub fn read_from_file(
path: Option<impl AsRef<Path>>,
) -> Result<Relations, RifError>
pub fn read_from_file( path: Option<impl AsRef<Path>>, ) -> Result<Relations, RifError>
Read rif file and return rif list