Skip to content

Commit

Permalink
Changed some clones to references and added some todos to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kinire98 committed Feb 5, 2024
1 parent 7f8fe10 commit 174b2e9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
4 changes: 2 additions & 2 deletions src/app/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<PathBuf as TryInto<OsType>>::try_into(dir.path()).unwrap(),
<PathBuf as TryInto<OsType>>::try_into(target_file.clone()).unwrap(),
<&PathBuf as TryInto<OsType>>::try_into(&dir.path()).unwrap(),
<&PathBuf as TryInto<OsType>>::try_into(&target_file).unwrap(),
),
dir.path().is_dir(),
) {
Expand Down
5 changes: 4 additions & 1 deletion src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -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<T>(file_to_backup: T, already_backed_file: T) -> bool
where
T: File,
{
if already_backed_file.just_created() {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ impl super::File for UnixFileTime {
self.just_created
}
}
impl TryFrom<PathBuf> for UnixFileTime {
impl TryFrom<&PathBuf> for UnixFileTime {
type Error = crate::error::Error;
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
fn try_from(value: &PathBuf) -> Result<Self, Self::Error> {
match fs::metadata(&value) {
Ok(file_metadata) => Ok(UnixFileTime {
creation_time: file_metadata.mtime(),
Expand Down
6 changes: 3 additions & 3 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl super::File for WindowsFileTime {
self.just_created
}
}
impl TryFrom<PathBuf> for WindowsFileTime {
impl TryFrom<&PathBuf> for WindowsFileTime {
type Error = crate::error::Error;
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
let path: Box<Path> = value.clone().into();
fn try_from(value: &PathBuf) -> Result<Self, Self::Error> {
let path: Box<Path> = value.into();
let metadata = match fs::metadata(value) {
Ok(time) => time,
Err(err) => match err.kind() {
Expand Down

0 comments on commit 174b2e9

Please sign in to comment.