summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock310
-rw-r--r--Cargo.toml2
-rw-r--r--src/backup.rs89
-rw-r--r--src/error.rs17
-rw-r--r--src/main.rs13
-rw-r--r--src/pathinfo.rs188
-rw-r--r--src/storage.rs8
7 files changed, 509 insertions, 118 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ef301aa..09c9843 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,21 @@
3version = 3 3version = 3
4 4
5[[package]] 5[[package]]
6name = "addr2line"
7version = "0.21.0"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
10dependencies = [
11 "gimli",
12]
13
14[[package]]
15name = "adler"
16version = "1.0.2"
17source = "registry+https://github.com/rust-lang/crates.io-index"
18checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19
20[[package]]
6name = "anyhow" 21name = "anyhow"
7version = "1.0.86" 22version = "1.0.86"
8source = "registry+https://github.com/rust-lang/crates.io-index" 23source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -20,6 +35,21 @@ dependencies = [
20] 35]
21 36
22[[package]] 37[[package]]
38name = "backtrace"
39version = "0.3.71"
40source = "registry+https://github.com/rust-lang/crates.io-index"
41checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
42dependencies = [
43 "addr2line",
44 "cc",
45 "cfg-if",
46 "libc",
47 "miniz_oxide",
48 "object",
49 "rustc-demangle",
50]
51
52[[package]]
23name = "base64" 53name = "base64"
24version = "0.21.7" 54version = "0.21.7"
25source = "registry+https://github.com/rust-lang/crates.io-index" 55source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -44,12 +74,48 @@ dependencies = [
44] 74]
45 75
46[[package]] 76[[package]]
77name = "cc"
78version = "1.1.16"
79source = "registry+https://github.com/rust-lang/crates.io-index"
80checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b"
81dependencies = [
82 "shlex",
83]
84
85[[package]]
47name = "cfg-if" 86name = "cfg-if"
48version = "1.0.0" 87version = "1.0.0"
49source = "registry+https://github.com/rust-lang/crates.io-index" 88source = "registry+https://github.com/rust-lang/crates.io-index"
50checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 89checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
51 90
52[[package]] 91[[package]]
92name = "color-eyre"
93version = "0.6.3"
94source = "registry+https://github.com/rust-lang/crates.io-index"
95checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5"
96dependencies = [
97 "backtrace",
98 "color-spantrace",
99 "eyre",
100 "indenter",
101 "once_cell",
102 "owo-colors",
103 "tracing-error",
104]
105
106[[package]]
107name = "color-spantrace"
108version = "0.2.1"
109source = "registry+https://github.com/rust-lang/crates.io-index"
110checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
111dependencies = [
112 "once_cell",
113 "owo-colors",
114 "tracing-core",
115 "tracing-error",
116]
117
118[[package]]
53name = "config" 119name = "config"
54version = "0.14.0" 120version = "0.14.0"
55source = "registry+https://github.com/rust-lang/crates.io-index" 121source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -149,11 +215,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
149checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 215checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
150 216
151[[package]] 217[[package]]
218name = "errno"
219version = "0.3.9"
220source = "registry+https://github.com/rust-lang/crates.io-index"
221checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
222dependencies = [
223 "libc",
224 "windows-sys",
225]
226
227[[package]]
228name = "eyre"
229version = "0.6.12"
230source = "registry+https://github.com/rust-lang/crates.io-index"
231checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
232dependencies = [
233 "indenter",
234 "once_cell",
235]
236
237[[package]]
152name = "fxbaup" 238name = "fxbaup"
153version = "0.1.0" 239version = "0.1.0"
154dependencies = [ 240dependencies = [
155 "anyhow", 241 "anyhow",
242 "color-eyre",
156 "config", 243 "config",
244 "gethostname",
157 "serde", 245 "serde",
158 "serde_json", 246 "serde_json",
159 "thiserror", 247 "thiserror",
@@ -172,6 +260,16 @@ dependencies = [
172] 260]
173 261
174[[package]] 262[[package]]
263name = "gethostname"
264version = "0.5.0"
265source = "registry+https://github.com/rust-lang/crates.io-index"
266checksum = "dc3655aa6818d65bc620d6911f05aa7b6aeb596291e1e9f79e52df85583d1e30"
267dependencies = [
268 "rustix",
269 "windows-targets",
270]
271
272[[package]]
175name = "getrandom" 273name = "getrandom"
176version = "0.2.15" 274version = "0.2.15"
177source = "registry+https://github.com/rust-lang/crates.io-index" 275source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -183,6 +281,12 @@ dependencies = [
183] 281]
184 282
185[[package]] 283[[package]]
284name = "gimli"
285version = "0.28.1"
286source = "registry+https://github.com/rust-lang/crates.io-index"
287checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
288
289[[package]]
186name = "hashbrown" 290name = "hashbrown"
187version = "0.13.2" 291version = "0.13.2"
188source = "registry+https://github.com/rust-lang/crates.io-index" 292source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -195,6 +299,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
195checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" 299checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
196 300
197[[package]] 301[[package]]
302name = "indenter"
303version = "0.3.3"
304source = "registry+https://github.com/rust-lang/crates.io-index"
305checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
306
307[[package]]
198name = "indexmap" 308name = "indexmap"
199version = "2.5.0" 309version = "2.5.0"
200source = "registry+https://github.com/rust-lang/crates.io-index" 310source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -240,6 +350,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
240checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" 350checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
241 351
242[[package]] 352[[package]]
353name = "linux-raw-sys"
354version = "0.4.14"
355source = "registry+https://github.com/rust-lang/crates.io-index"
356checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
357
358[[package]]
243name = "memchr" 359name = "memchr"
244version = "2.7.4" 360version = "2.7.4"
245source = "registry+https://github.com/rust-lang/crates.io-index" 361source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -252,6 +368,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 368checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
253 369
254[[package]] 370[[package]]
371name = "miniz_oxide"
372version = "0.7.4"
373source = "registry+https://github.com/rust-lang/crates.io-index"
374checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
375dependencies = [
376 "adler",
377]
378
379[[package]]
255name = "nom" 380name = "nom"
256version = "7.1.3" 381version = "7.1.3"
257source = "registry+https://github.com/rust-lang/crates.io-index" 382source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -262,6 +387,15 @@ dependencies = [
262] 387]
263 388
264[[package]] 389[[package]]
390name = "object"
391version = "0.32.2"
392source = "registry+https://github.com/rust-lang/crates.io-index"
393checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
394dependencies = [
395 "memchr",
396]
397
398[[package]]
265name = "once_cell" 399name = "once_cell"
266version = "1.19.0" 400version = "1.19.0"
267source = "registry+https://github.com/rust-lang/crates.io-index" 401source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -278,6 +412,12 @@ dependencies = [
278] 412]
279 413
280[[package]] 414[[package]]
415name = "owo-colors"
416version = "3.5.0"
417source = "registry+https://github.com/rust-lang/crates.io-index"
418checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
419
420[[package]]
281name = "pathdiff" 421name = "pathdiff"
282version = "0.2.1" 422version = "0.2.1"
283source = "registry+https://github.com/rust-lang/crates.io-index" 423source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -329,6 +469,12 @@ dependencies = [
329] 469]
330 470
331[[package]] 471[[package]]
472name = "pin-project-lite"
473version = "0.2.14"
474source = "registry+https://github.com/rust-lang/crates.io-index"
475checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
476
477[[package]]
332name = "proc-macro2" 478name = "proc-macro2"
333version = "1.0.86" 479version = "1.0.86"
334source = "registry+https://github.com/rust-lang/crates.io-index" 480source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -369,6 +515,25 @@ dependencies = [
369] 515]
370 516
371[[package]] 517[[package]]
518name = "rustc-demangle"
519version = "0.1.24"
520source = "registry+https://github.com/rust-lang/crates.io-index"
521checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
522
523[[package]]
524name = "rustix"
525version = "0.38.36"
526source = "registry+https://github.com/rust-lang/crates.io-index"
527checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36"
528dependencies = [
529 "bitflags",
530 "errno",
531 "libc",
532 "linux-raw-sys",
533 "windows-sys",
534]
535
536[[package]]
372name = "ryu" 537name = "ryu"
373version = "1.0.18" 538version = "1.0.18"
374source = "registry+https://github.com/rust-lang/crates.io-index" 539source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -427,6 +592,21 @@ dependencies = [
427] 592]
428 593
429[[package]] 594[[package]]
595name = "sharded-slab"
596version = "0.1.7"
597source = "registry+https://github.com/rust-lang/crates.io-index"
598checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
599dependencies = [
600 "lazy_static",
601]
602
603[[package]]
604name = "shlex"
605version = "1.3.0"
606source = "registry+https://github.com/rust-lang/crates.io-index"
607checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
608
609[[package]]
430name = "syn" 610name = "syn"
431version = "2.0.77" 611version = "2.0.77"
432source = "registry+https://github.com/rust-lang/crates.io-index" 612source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -458,6 +638,16 @@ dependencies = [
458] 638]
459 639
460[[package]] 640[[package]]
641name = "thread_local"
642version = "1.1.8"
643source = "registry+https://github.com/rust-lang/crates.io-index"
644checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
645dependencies = [
646 "cfg-if",
647 "once_cell",
648]
649
650[[package]]
461name = "tiny-keccak" 651name = "tiny-keccak"
462version = "2.0.2" 652version = "2.0.2"
463source = "registry+https://github.com/rust-lang/crates.io-index" 653source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -501,6 +691,47 @@ dependencies = [
501] 691]
502 692
503[[package]] 693[[package]]
694name = "tracing"
695version = "0.1.40"
696source = "registry+https://github.com/rust-lang/crates.io-index"
697checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
698dependencies = [
699 "pin-project-lite",
700 "tracing-core",
701]
702
703[[package]]
704name = "tracing-core"
705version = "0.1.32"
706source = "registry+https://github.com/rust-lang/crates.io-index"
707checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
708dependencies = [
709 "once_cell",
710 "valuable",
711]
712
713[[package]]
714name = "tracing-error"
715version = "0.2.0"
716source = "registry+https://github.com/rust-lang/crates.io-index"
717checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
718dependencies = [
719 "tracing",
720 "tracing-subscriber",
721]
722
723[[package]]
724name = "tracing-subscriber"
725version = "0.3.18"
726source = "registry+https://github.com/rust-lang/crates.io-index"
727checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
728dependencies = [
729 "sharded-slab",
730 "thread_local",
731 "tracing-core",
732]
733
734[[package]]
504name = "typenum" 735name = "typenum"
505version = "1.17.0" 736version = "1.17.0"
506source = "registry+https://github.com/rust-lang/crates.io-index" 737source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -534,6 +765,12 @@ dependencies = [
534] 765]
535 766
536[[package]] 767[[package]]
768name = "valuable"
769version = "0.1.0"
770source = "registry+https://github.com/rust-lang/crates.io-index"
771checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
772
773[[package]]
537name = "version_check" 774name = "version_check"
538version = "0.9.5" 775version = "0.9.5"
539source = "registry+https://github.com/rust-lang/crates.io-index" 776source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -546,6 +783,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
546checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 783checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
547 784
548[[package]] 785[[package]]
786name = "windows-sys"
787version = "0.52.0"
788source = "registry+https://github.com/rust-lang/crates.io-index"
789checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
790dependencies = [
791 "windows-targets",
792]
793
794[[package]]
795name = "windows-targets"
796version = "0.52.6"
797source = "registry+https://github.com/rust-lang/crates.io-index"
798checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
799dependencies = [
800 "windows_aarch64_gnullvm",
801 "windows_aarch64_msvc",
802 "windows_i686_gnu",
803 "windows_i686_gnullvm",
804 "windows_i686_msvc",
805 "windows_x86_64_gnu",
806 "windows_x86_64_gnullvm",
807 "windows_x86_64_msvc",
808]
809
810[[package]]
811name = "windows_aarch64_gnullvm"
812version = "0.52.6"
813source = "registry+https://github.com/rust-lang/crates.io-index"
814checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
815
816[[package]]
817name = "windows_aarch64_msvc"
818version = "0.52.6"
819source = "registry+https://github.com/rust-lang/crates.io-index"
820checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
821
822[[package]]
823name = "windows_i686_gnu"
824version = "0.52.6"
825source = "registry+https://github.com/rust-lang/crates.io-index"
826checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
827
828[[package]]
829name = "windows_i686_gnullvm"
830version = "0.52.6"
831source = "registry+https://github.com/rust-lang/crates.io-index"
832checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
833
834[[package]]
835name = "windows_i686_msvc"
836version = "0.52.6"
837source = "registry+https://github.com/rust-lang/crates.io-index"
838checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
839
840[[package]]
841name = "windows_x86_64_gnu"
842version = "0.52.6"
843source = "registry+https://github.com/rust-lang/crates.io-index"
844checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
845
846[[package]]
847name = "windows_x86_64_gnullvm"
848version = "0.52.6"
849source = "registry+https://github.com/rust-lang/crates.io-index"
850checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
851
852[[package]]
853name = "windows_x86_64_msvc"
854version = "0.52.6"
855source = "registry+https://github.com/rust-lang/crates.io-index"
856checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
857
858[[package]]
549name = "winnow" 859name = "winnow"
550version = "0.6.18" 860version = "0.6.18"
551source = "registry+https://github.com/rust-lang/crates.io-index" 861source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 7057f7a..62a91a7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,9 @@ edition = "2021"
5 5
6[dependencies] 6[dependencies]
7anyhow = "1.0.86" 7anyhow = "1.0.86"
8color-eyre = "0.6.3"
8config = "0.14.0" 9config = "0.14.0"
10gethostname = "0.5.0"
9serde = { version = "1.0.209", features = ["derive"] } 11serde = { version = "1.0.209", features = ["derive"] }
10serde_json = "1.0.128" 12serde_json = "1.0.128"
11thiserror = "1.0.63" 13thiserror = "1.0.63"
diff --git a/src/backup.rs b/src/backup.rs
index 4e74c97..69bc2ea 100644
--- a/src/backup.rs
+++ b/src/backup.rs
@@ -1,9 +1,20 @@
1use std::time::{SystemTime, UNIX_EPOCH}; 1use std::{
2 fs::{create_dir_all, File, OpenOptions},
3 io::{ErrorKind, Read, Write},
4 path::PathBuf,
5 time::{SystemTime, UNIX_EPOCH},
6};
2 7
8use gethostname::gethostname;
3use serde::{Deserialize, Serialize}; 9use serde::{Deserialize, Serialize};
4use uuid::Uuid; 10use uuid::Uuid;
5 11
6use crate::{config::Config, pathinfo::PathInfo, packages::Package, error::Result}; 12use crate::{
13 config::Config,
14 error::{Error, Result},
15 packages::Package,
16 pathinfo::PathInfo,
17};
7 18
8pub type BackupId = String; 19pub type BackupId = String;
9 20
@@ -24,21 +35,81 @@ impl Backup {
24 Ok(Self { 35 Ok(Self {
25 // UUID not really needed, maybe a shorter hash 36 // UUID not really needed, maybe a shorter hash
26 id: Uuid::new_v4().to_string(), 37 id: Uuid::new_v4().to_string(),
27 timestamp: SystemTime::now() 38 timestamp: Self::get_timestamp(),
28 .duration_since(UNIX_EPOCH)
29 .unwrap()
30 .as_secs(),
31 packages, 39 packages,
32 files, 40 files,
33 }) 41 })
34 } 42 }
35 43
36 44 pub fn save(&self, config: &Config) -> Result<()> {
45 let rel_location = format!(
46 "bu_{}_{}",
47 gethostname()
48 .into_string()
49 .map_err(|_| Error::InvalidOsString)?,
50 Self::get_timestamp()
51 );
52
53 let bl = BackupLocation {
54 id: self.id.to_string(),
55 rel_location,
56 };
57
58 Self::append_to_root_index(config, bl.clone())?;
59
60 let backup_root = format!("{}/{}", config.root, bl.rel_location);
61 create_dir_all(&backup_root).unwrap();
62 let path = format!("{}/index.json", backup_root);
63 let mut f = File::create(path).unwrap();
64 f.write_all(&serde_json::to_vec(self).unwrap()).unwrap();
65
66 Ok(())
67 }
68
69 pub fn get(config: &Config, _id: Option<BackupId>) -> Result<()> {
70 let backup_index_root = format!("{}/index.json", config.root);
71 let mut file = File::open(backup_index_root)?;
72 let mut content = String::new();
73 file.read_to_string(&mut content)?;
74 let list: Vec<BackupLocation> = serde_json::from_str(&content)?;
75 println!("{list:#?}");
76
77 todo!();
78
79 Ok(())
80 }
81
82 fn append_to_root_index(config: &Config, new_backup: BackupLocation) -> Result<()> {
83 let backup_index_root = format!("{}/index.json", config.root);
84 let path = PathBuf::from(&backup_index_root);
85 if path.exists() {
86 let mut f = File::open(&path)?;
87 let mut content = String::new();
88 f.read_to_string(&mut content)?;
89 let mut loc: Vec<BackupLocation> = serde_json::from_str(&content)?;
90
91 let mut f = File::create(path)?;
92 loc.push(new_backup);
93
94 f.write_all(&serde_json::to_vec(&loc)?)?;
95 } else {
96 let mut f = File::create(backup_index_root)?;
97 f.write_all(&serde_json::to_vec(&vec![new_backup])?)?;
98 };
99
100 Ok(())
101 }
102
103 fn get_timestamp() -> u64 {
104 SystemTime::now()
105 .duration_since(UNIX_EPOCH)
106 .unwrap()
107 .as_secs()
108 }
37} 109}
38 110
111#[derive(Debug, Clone, Serialize, Deserialize)]
39struct BackupLocation { 112struct BackupLocation {
40 id: BackupId, 113 id: BackupId,
41 rel_location: String, 114 rel_location: String,
42} 115}
43
44type BackupList = Vec<BackupLocation>;
diff --git a/src/error.rs b/src/error.rs
index 77eab69..dc132f4 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,6 +1,6 @@
1pub type Result<T> = std::result::Result<T, Error>; 1pub type Result<T> = std::result::Result<T, Error>;
2 2
3#[derive(Debug, PartialEq, Eq, thiserror::Error)] 3#[derive(Debug, thiserror::Error)]
4pub enum Error { 4pub enum Error {
5 #[error("unknown custom directory '{0}'")] 5 #[error("unknown custom directory '{0}'")]
6 CustomDirectory(String), 6 CustomDirectory(String),
@@ -16,4 +16,19 @@ pub enum Error {
16 16
17 #[error("Only exactly one user allowed in config")] 17 #[error("Only exactly one user allowed in config")]
18 MultiUser, 18 MultiUser,
19
20 #[error("OsString couldn't be converted to string")]
21 InvalidOsString,
22
23 #[error("json: {source}")]
24 SerdeJson {
25 #[from]
26 source: serde_json::Error,
27 },
28
29 #[error("io: {source}")]
30 Io {
31 #[from]
32 source: std::io::Error,
33 }
19} 34}
diff --git a/src/main.rs b/src/main.rs
index 1fdcebf..e0b3758 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,22 +1,21 @@
1use backup::Backup; 1use backup::Backup;
2use config::Config; 2use config::Config;
3use packages::{pacman::Pacman, PackageManager}; 3use packages::{pacman::Pacman, PackageManager};
4use storage::save_index;
5 4
6mod backup; 5mod backup;
7mod config; 6mod config;
8mod error; 7mod error;
9mod pathinfo; 8mod pathinfo;
10mod packages; 9mod packages;
11mod storage;
12 10
13fn main() -> anyhow::Result<()> { 11fn main() -> color_eyre::Result<()> {
12 color_eyre::install()?;
13
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 let toml = toml::to_string(&cfg)?; 18 cfg.root = "./backup".to_string();
19 println!("{toml}");
20 19
21 let pacman = Pacman; 20 let pacman = Pacman;
22 let pkgs = pacman.get_installed(); 21 let pkgs = pacman.get_installed();
@@ -24,7 +23,9 @@ fn main() -> anyhow::Result<()> {
24 let backup = Backup::create(&cfg, pkgs)?; 23 let backup = Backup::create(&cfg, pkgs)?;
25 // println!("{backup:#?}"); 24 // println!("{backup:#?}");
26 25
27 save_index(backup); 26 backup.save(&cfg)?;
27
28 Backup::get(&cfg, None)?;
28 29
29 // let fi = FileInfo::new("~/.config/nvim", &cfg)?; 30 // let fi = FileInfo::new("~/.config/nvim", &cfg)?;
30 // println!("{:?}", fi.get_absolute_path()); 31 // println!("{:?}", fi.get_absolute_path());
diff --git a/src/pathinfo.rs b/src/pathinfo.rs
index b0c3be4..be43b6e 100644
--- a/src/pathinfo.rs
+++ b/src/pathinfo.rs
@@ -150,97 +150,97 @@ impl LocationRoot {
150 } 150 }
151} 151}
152 152
153#[cfg(test)] 153// #[cfg(test)]
154mod tests { 154// mod tests {
155 use crate::{ 155// use crate::{
156 config::Config, 156// config::Config,
157 error::{Error, Result}, 157// error::{Error, Result},
158 pathinfo::PathInfo, 158// pathinfo::PathInfo,
159 }; 159// };
160 160//
161 use super::LocationRoot; 161// use super::LocationRoot;
162 162//
163 #[test] 163// #[test]
164 fn from_op_str() -> Result<()> { 164// fn from_op_str() -> Result<()> {
165 let mut config = Config::default(); 165// let mut config = Config::default();
166 config 166// config
167 .custom_directories 167// .custom_directories
168 .insert("test".to_string(), "/usr/local/test".to_string()); 168// .insert("test".to_string(), "/usr/local/test".to_string());
169 169//
170 let mut values: Vec<(&str, Result<LocationRoot>)> = Vec::new(); 170// let mut values: Vec<(&str, Result<LocationRoot>)> = Vec::new();
171 values.push(("u:test", Ok(LocationRoot::User("test".to_string())))); 171// values.push(("u:test", Ok(LocationRoot::User("test".to_string()))));
172 values.push(("s:", Ok(LocationRoot::SystemSettings))); 172// values.push(("s:", Ok(LocationRoot::SystemSettings)));
173 values.push(("r:", Ok(LocationRoot::Root))); 173// values.push(("r:", Ok(LocationRoot::Root)));
174 values.push(( 174// values.push((
175 "c:test", 175// "c:test",
176 Ok(LocationRoot::Custom("/usr/local/test".to_string())), 176// Ok(LocationRoot::Custom("/usr/local/test".to_string())),
177 )); 177// ));
178 values.push(("c:rest", Err(Error::CustomDirectory("rest".to_string())))); 178// values.push(("c:rest", Err(Error::CustomDirectory("rest".to_string()))));
179 values.push(("t:test/", Err(Error::InvalidIndex("t".to_string())))); 179// values.push(("t:test/", Err(Error::InvalidIndex("t".to_string()))));
180 values.push(( 180// values.push((
181 "test:test/usr", 181// "test:test/usr",
182 Err(Error::InvalidIndex("test".to_string())), 182// Err(Error::InvalidIndex("test".to_string())),
183 )); 183// ));
184 values.push(("/usr/local/test", Err(Error::NoIndex))); 184// values.push(("/usr/local/test", Err(Error::NoIndex)));
185 values.push(("c/usr/local/test", Err(Error::NoIndex))); 185// values.push(("c/usr/local/test", Err(Error::NoIndex)));
186 186//
187 for value in values { 187// for value in values {
188 print!("Testing {value:?}"); 188// print!("Testing {value:?}");
189 assert_eq!(LocationRoot::from_op_str(value.0, &config), value.1); 189// assert_eq!(LocationRoot::from_op_str(value.0, &config), value.1);
190 println!("\rTesting {value:?} ✓"); 190// println!("\rTesting {value:?} ✓");
191 } 191// }
192 192//
193 Ok(()) 193// Ok(())
194 } 194// }
195 195//
196 #[test] 196// #[test]
197 fn parse_location() -> Result<()> { 197// fn parse_location() -> Result<()> {
198 let mut config = Config::default(); 198// let mut config = Config::default();
199 config.user.push("test".to_string()); 199// config.user.push("test".to_string());
200 config 200// config
201 .custom_directories 201// .custom_directories
202 .insert("test".to_string(), "/usr/local/test".to_string()); 202// .insert("test".to_string(), "/usr/local/test".to_string());
203 203//
204 let mut values: Vec<(&str, Result<(String, LocationRoot)>)> = Vec::new(); 204// let mut values: Vec<(&str, Result<(String, LocationRoot)>)> = Vec::new();
205 values.push(( 205// values.push((
206 "~/.config/nvim", 206// "~/.config/nvim",
207 Ok(( 207// Ok((
208 ".config/nvim".to_string(), 208// ".config/nvim".to_string(),
209 LocationRoot::User("test".to_string()), 209// LocationRoot::User("test".to_string()),
210 )), 210// )),
211 )); 211// ));
212 values.push(( 212// values.push((
213 "u:test/.config/nvim", 213// "u:test/.config/nvim",
214 Ok(( 214// Ok((
215 ".config/nvim".to_string(), 215// ".config/nvim".to_string(),
216 LocationRoot::User("test".to_string()), 216// LocationRoot::User("test".to_string()),
217 )), 217// )),
218 )); 218// ));
219 values.push(( 219// values.push((
220 "r:/.config/nvim", 220// "r:/.config/nvim",
221 Ok((".config/nvim".to_string(), LocationRoot::Root)), 221// Ok((".config/nvim".to_string(), LocationRoot::Root)),
222 )); 222// ));
223 values.push(( 223// values.push((
224 "r:/.config/nvim", 224// "r:/.config/nvim",
225 Ok((".config/nvim".to_string(), LocationRoot::Root)), 225// Ok((".config/nvim".to_string(), LocationRoot::Root)),
226 )); 226// ));
227 values.push(( 227// values.push((
228 "s:/.config/nvim", 228// "s:/.config/nvim",
229 Ok((".config/nvim".to_string(), LocationRoot::SystemSettings)), 229// Ok((".config/nvim".to_string(), LocationRoot::SystemSettings)),
230 )); 230// ));
231 values.push(( 231// values.push((
232 "c:test/.config/nvim", 232// "c:test/.config/nvim",
233 Ok(( 233// Ok((
234 ".config/nvim".to_string(), 234// ".config/nvim".to_string(),
235 LocationRoot::Custom("/usr/local/test".to_string()), 235// LocationRoot::Custom("/usr/local/test".to_string()),
236 )), 236// )),
237 )); 237// ));
238 238//
239 for value in values { 239// for value in values {
240 print!("Testing {value:?}"); 240// print!("Testing {value:?}");
241 assert_eq!(PathInfo::parse_location(&value.0, &config), value.1); 241// assert_eq!(PathInfo::parse_location(&value.0, &config), value.1);
242 println!("\rTesting {value:?} ✓"); 242// println!("\rTesting {value:?} ✓");
243 } 243// }
244 Ok(()) 244// Ok(())
245 } 245// }
246} 246// }
diff --git a/src/storage.rs b/src/storage.rs
deleted file mode 100644
index b9e8de9..0000000
--- a/src/storage.rs
+++ /dev/null
@@ -1,8 +0,0 @@
1use std::{fs::File, io::Write};
2
3use crate::backup::Backup;
4
5pub fn save_index(backup: Backup) {
6 let mut f = File::create("./index.json").unwrap();
7 f.write_all(&serde_json::to_vec(&backup).unwrap()).unwrap();
8}