diff --git a/README.md b/README.md index 7c5d6cc..aae1658 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ klone is a simple backup tool that saves the most recent copy of your files. If ``` The objectives of this application: As a user: make simple backups with the most recent copy of the files and access them in a simple way through the OS fs, without the need to use an external app: -1. Iterate through the directories. -2. Get the times of modification of each file in the directory of origin directory. -3. Get the times of modification of each file in the directory of target directory. -4. Compare both. If the origin directory time is greater than the target directory time that means that there were some changes, so it's neccessary to make a backup. -5. If a directory or a file doesn't exist in the target directory it will be created. +1. Iterate through the directories. (DONE) +2. Get the times of modification of each file in the directory of origin directory. (DONE) +3. Get the times of modification of each file in the directory of target directory. (DONE) +4. Compare both. If the origin directory time is greater than the target directory time that means that there were some changes, so it's neccessary to make a backup. (DONE) +5. If a directory or a file doesn't exist in the target directory it will be created. (DONE) 6. If a directory or a file no longer exists in the origin directory two options: if nothing is addressed for this, it will just leave it there or you can delete it. 7. All of this will be created in the most recent directory of the backup directory. @@ -32,3 +32,6 @@ You can tell the application to create a new directory so you can store the hist - Make an option to exclude directories - An option to store the configuration in a configuration file, so you don't have to indicate the paths or the exclusions all the time. (Maybe with a [tui](https://docs.rs/tui/latest/tui)). It will also be useful to show progress - A way to make differential and incremental backups. This is improbable because it defeats the purpose of the application. +## TODOS +- Add behaviour for Windows when file or dir doesn't exist +- Change transfer of ownership to reference passing to avoid clones and improve performance time and memory wise diff --git a/src/app/operations.rs b/src/app/operations.rs index 235069e..9888e47 100644 --- a/src/app/operations.rs +++ b/src/app/operations.rs @@ -30,8 +30,8 @@ pub fn backup_operations( // We check if the directory should be backed and if its a directory match ( should_be_backed( - >::try_into(dir.path()).unwrap(), - >::try_into(target_file.clone()).unwrap(), + <&PathBuf as TryInto>::try_into(&dir.path()).unwrap(), + <&PathBuf as TryInto>::try_into(&target_file).unwrap(), ), dir.path().is_dir(), ) { diff --git a/src/sys/mod.rs b/src/sys/mod.rs index eef7ace..3700c21 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -1,4 +1,7 @@ -pub fn should_be_backed(file_to_backup: impl File, already_backed_file: impl File) -> bool { +pub fn should_be_backed(file_to_backup: T, already_backed_file: T) -> bool +where + T: File, +{ if already_backed_file.just_created() { return true; } diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 35322de..a4a4113 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -16,9 +16,9 @@ impl super::File for UnixFileTime { self.just_created } } -impl TryFrom for UnixFileTime { +impl TryFrom<&PathBuf> for UnixFileTime { type Error = crate::error::Error; - fn try_from(value: PathBuf) -> Result { + fn try_from(value: &PathBuf) -> Result { match fs::metadata(&value) { Ok(file_metadata) => Ok(UnixFileTime { creation_time: file_metadata.mtime(), diff --git a/src/sys/windows.rs b/src/sys/windows.rs index b998333..26f0f04 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -19,10 +19,10 @@ impl super::File for WindowsFileTime { self.just_created } } -impl TryFrom for WindowsFileTime { +impl TryFrom<&PathBuf> for WindowsFileTime { type Error = crate::error::Error; - fn try_from(value: PathBuf) -> Result { - let path: Box = value.clone().into(); + fn try_from(value: &PathBuf) -> Result { + let path: Box = value.into(); let metadata = match fs::metadata(value) { Ok(time) => time, Err(err) => match err.kind() {