summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs4
-rw-r--r--src/packages.rs2
-rw-r--r--src/pathinfo.rs41
4 files changed, 37 insertions, 12 deletions
diff --git a/src/error.rs b/src/error.rs
index c43c1fc..0cf4dca 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -34,5 +34,5 @@ pub enum Error {
34 Io { 34 Io {
35 #[from] 35 #[from]
36 source: std::io::Error, 36 source: std::io::Error,
37 } 37 },
38} 38}
diff --git a/src/main.rs b/src/main.rs
index acb728f..e67e535 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,8 +5,8 @@ use packages::{pacman::Pacman, PackageManager};
5mod backup; 5mod backup;
6mod config; 6mod config;
7mod error; 7mod error;
8mod pathinfo;
9mod packages; 8mod packages;
9mod pathinfo;
10 10
11fn main() -> color_eyre::Result<()> { 11fn main() -> color_eyre::Result<()> {
12 color_eyre::install()?; 12 color_eyre::install()?;
@@ -14,7 +14,7 @@ fn main() -> color_eyre::Result<()> {
14 let mut cfg = Config::load()?; 14 let mut cfg = Config::load()?;
15 cfg.user.push("fx".to_string()); 15 cfg.user.push("fx".to_string());
16 cfg.directories.push("~/.config/nvim".to_string()); 16 cfg.directories.push("~/.config/nvim".to_string());
17 cfg.directories.push("~/.config/hypr".to_string()); 17 // cfg.directories.push("~/.config/hypr".to_string());
18 cfg.root = "./backup".to_string(); 18 cfg.root = "./backup".to_string();
19 // cfg.root = "./backup-test".to_string(); 19 // cfg.root = "./backup-test".to_string();
20 // cfg.directories.push("u:/code/proj/fxbaup/backup-test-dir".to_string()); 20 // cfg.directories.push("u:/code/proj/fxbaup/backup-test-dir".to_string());
diff --git a/src/packages.rs b/src/packages.rs
index 7ac1736..e7b4c3d 100644
--- a/src/packages.rs
+++ b/src/packages.rs
@@ -9,7 +9,7 @@ pub mod portage;
9pub struct Package { 9pub struct Package {
10 pub id: String, 10 pub id: String,
11 pub version: String, 11 pub version: String,
12 pub explicit: bool 12 pub explicit: bool,
13} 13}
14 14
15pub trait PackageManager { 15pub trait PackageManager {
diff --git a/src/pathinfo.rs b/src/pathinfo.rs
index 641e7ef..3e4b5c2 100644
--- a/src/pathinfo.rs
+++ b/src/pathinfo.rs
@@ -52,6 +52,7 @@ impl PathInfo {
52 // FIX: Check if new last modified is newer than old one 52 // FIX: Check if new last modified is newer than old one
53 last_modified = handle.last_modified.clone(); 53 last_modified = handle.last_modified.clone();
54 }; 54 };
55 last_modified = None;
55 children.push(handle); 56 children.push(handle);
56 } 57 }
57 Self { 58 Self {
@@ -94,10 +95,8 @@ impl PathInfo {
94 return Ok(None); 95 return Ok(None);
95 }; 96 };
96 97
97
98 let files = last_backup.files.clone(); 98 let files = last_backup.files.clone();
99 let last_file_opt = files.iter().find(|file| file.rel_location == rel_location && file.location_root == *location_root); 99 let last_file_opt = Self::find_last_modified(files, rel_location, location_root);
100
101 let Some(last_file) = last_file_opt else { 100 let Some(last_file) = last_file_opt else {
102 // File didn't exist last Backup 101 // File didn't exist last Backup
103 println!("File didn't exist last Backup"); 102 println!("File didn't exist last Backup");
@@ -133,6 +132,32 @@ impl PathInfo {
133 Ok(Some(modified_backup.id.clone())) 132 Ok(Some(modified_backup.id.clone()))
134 } 133 }
135 134
135 pub fn find_last_modified(
136 files: Vec<Self>,
137 rel_location: &str,
138 location_root: &LocationRoot,
139 ) -> Option<PathInfo> {
140 for path in files {
141 if path.is_file {
142 println!("Checking {}", path.rel_location);
143 println!("File rel: {} ?= {}", path.rel_location, rel_location);
144 println!("File rot: {} ?= {}", path.location_root, location_root);
145 if path.rel_location == rel_location && path.location_root == *location_root {
146 println!("Return Some");
147 return Some(path);
148 };
149 } else {
150 println!("Checking all in {path:?}");
151 let is_modified =
152 PathInfo::find_last_modified(path.children, rel_location, location_root);
153 if is_modified.is_some() {
154 return is_modified;
155 };
156 }
157 }
158 None
159 }
160
136 pub fn get_absolute_path(&self) -> PathBuf { 161 pub fn get_absolute_path(&self) -> PathBuf {
137 Self::get_abs_path(&self.location_root.to_string(), &self.rel_location) 162 Self::get_abs_path(&self.location_root.to_string(), &self.rel_location)
138 } 163 }
@@ -142,11 +167,7 @@ impl PathInfo {
142 return Ok(()); 167 return Ok(());
143 } 168 }
144 println!("Save File {:?}", self.rel_location); 169 println!("Save File {:?}", self.rel_location);
145 if !self.is_file { 170 if self.is_file {
146 for child in &self.children {
147 child.save(backup_root)?;
148 }
149 } else {
150 let new_path = format!("{}/{}", backup_root, self.rel_location); 171 let new_path = format!("{}/{}", backup_root, self.rel_location);
151 // println!("New Path: {new_path}"); 172 // println!("New Path: {new_path}");
152 // println!("Old Path: {:?}", self.get_absolute_path()); 173 // println!("Old Path: {:?}", self.get_absolute_path());
@@ -155,6 +176,10 @@ impl PathInfo {
155 create_dir_all(parent)?; 176 create_dir_all(parent)?;
156 } 177 }
157 std::fs::copy(self.get_absolute_path(), new_path)?; 178 std::fs::copy(self.get_absolute_path(), new_path)?;
179 } else {
180 for child in &self.children {
181 child.save(backup_root)?;
182 }
158 }; 183 };
159 184
160 Ok(()) 185 Ok(())