diff options
author | fxqnlr <[email protected]> | 2024-09-06 13:47:47 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-06 13:47:47 +0200 |
commit | ab7f99e061e54924899b778e929dd2e17c8792d9 (patch) | |
tree | 644dc766f954b7a5e04cf7658821a5b5694f764b | |
parent | 3e1cb020d5449849b37874f91cadfa4a9c878747 (diff) | |
download | arbs-ab7f99e061e54924899b778e929dd2e17c8792d9.tar arbs-ab7f99e061e54924899b778e929dd2e17c8792d9.tar.gz arbs-ab7f99e061e54924899b778e929dd2e17c8792d9.zip |
add root index and directory creation
-rw-r--r-- | Cargo.lock | 310 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/backup.rs | 89 | ||||
-rw-r--r-- | src/error.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 13 | ||||
-rw-r--r-- | src/pathinfo.rs | 188 | ||||
-rw-r--r-- | src/storage.rs | 8 |
7 files changed, 509 insertions, 118 deletions
@@ -3,6 +3,21 @@ | |||
3 | version = 3 | 3 | version = 3 |
4 | 4 | ||
5 | [[package]] | 5 | [[package]] |
6 | name = "addr2line" | ||
7 | version = "0.21.0" | ||
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
9 | checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" | ||
10 | dependencies = [ | ||
11 | "gimli", | ||
12 | ] | ||
13 | |||
14 | [[package]] | ||
15 | name = "adler" | ||
16 | version = "1.0.2" | ||
17 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" | ||
19 | |||
20 | [[package]] | ||
6 | name = "anyhow" | 21 | name = "anyhow" |
7 | version = "1.0.86" | 22 | version = "1.0.86" |
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | 23 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -20,6 +35,21 @@ dependencies = [ | |||
20 | ] | 35 | ] |
21 | 36 | ||
22 | [[package]] | 37 | [[package]] |
38 | name = "backtrace" | ||
39 | version = "0.3.71" | ||
40 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
41 | checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" | ||
42 | dependencies = [ | ||
43 | "addr2line", | ||
44 | "cc", | ||
45 | "cfg-if", | ||
46 | "libc", | ||
47 | "miniz_oxide", | ||
48 | "object", | ||
49 | "rustc-demangle", | ||
50 | ] | ||
51 | |||
52 | [[package]] | ||
23 | name = "base64" | 53 | name = "base64" |
24 | version = "0.21.7" | 54 | version = "0.21.7" |
25 | source = "registry+https://github.com/rust-lang/crates.io-index" | 55 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -44,12 +74,48 @@ dependencies = [ | |||
44 | ] | 74 | ] |
45 | 75 | ||
46 | [[package]] | 76 | [[package]] |
77 | name = "cc" | ||
78 | version = "1.1.16" | ||
79 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
80 | checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" | ||
81 | dependencies = [ | ||
82 | "shlex", | ||
83 | ] | ||
84 | |||
85 | [[package]] | ||
47 | name = "cfg-if" | 86 | name = "cfg-if" |
48 | version = "1.0.0" | 87 | version = "1.0.0" |
49 | source = "registry+https://github.com/rust-lang/crates.io-index" | 88 | source = "registry+https://github.com/rust-lang/crates.io-index" |
50 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | 89 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
51 | 90 | ||
52 | [[package]] | 91 | [[package]] |
92 | name = "color-eyre" | ||
93 | version = "0.6.3" | ||
94 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
95 | checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" | ||
96 | dependencies = [ | ||
97 | "backtrace", | ||
98 | "color-spantrace", | ||
99 | "eyre", | ||
100 | "indenter", | ||
101 | "once_cell", | ||
102 | "owo-colors", | ||
103 | "tracing-error", | ||
104 | ] | ||
105 | |||
106 | [[package]] | ||
107 | name = "color-spantrace" | ||
108 | version = "0.2.1" | ||
109 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
110 | checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" | ||
111 | dependencies = [ | ||
112 | "once_cell", | ||
113 | "owo-colors", | ||
114 | "tracing-core", | ||
115 | "tracing-error", | ||
116 | ] | ||
117 | |||
118 | [[package]] | ||
53 | name = "config" | 119 | name = "config" |
54 | version = "0.14.0" | 120 | version = "0.14.0" |
55 | source = "registry+https://github.com/rust-lang/crates.io-index" | 121 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -149,11 +215,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
149 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" | 215 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" |
150 | 216 | ||
151 | [[package]] | 217 | [[package]] |
218 | name = "errno" | ||
219 | version = "0.3.9" | ||
220 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
221 | checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" | ||
222 | dependencies = [ | ||
223 | "libc", | ||
224 | "windows-sys", | ||
225 | ] | ||
226 | |||
227 | [[package]] | ||
228 | name = "eyre" | ||
229 | version = "0.6.12" | ||
230 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
231 | checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" | ||
232 | dependencies = [ | ||
233 | "indenter", | ||
234 | "once_cell", | ||
235 | ] | ||
236 | |||
237 | [[package]] | ||
152 | name = "fxbaup" | 238 | name = "fxbaup" |
153 | version = "0.1.0" | 239 | version = "0.1.0" |
154 | dependencies = [ | 240 | dependencies = [ |
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]] |
263 | name = "gethostname" | ||
264 | version = "0.5.0" | ||
265 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
266 | checksum = "dc3655aa6818d65bc620d6911f05aa7b6aeb596291e1e9f79e52df85583d1e30" | ||
267 | dependencies = [ | ||
268 | "rustix", | ||
269 | "windows-targets", | ||
270 | ] | ||
271 | |||
272 | [[package]] | ||
175 | name = "getrandom" | 273 | name = "getrandom" |
176 | version = "0.2.15" | 274 | version = "0.2.15" |
177 | source = "registry+https://github.com/rust-lang/crates.io-index" | 275 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -183,6 +281,12 @@ dependencies = [ | |||
183 | ] | 281 | ] |
184 | 282 | ||
185 | [[package]] | 283 | [[package]] |
284 | name = "gimli" | ||
285 | version = "0.28.1" | ||
286 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
287 | checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" | ||
288 | |||
289 | [[package]] | ||
186 | name = "hashbrown" | 290 | name = "hashbrown" |
187 | version = "0.13.2" | 291 | version = "0.13.2" |
188 | source = "registry+https://github.com/rust-lang/crates.io-index" | 292 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -195,6 +299,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
195 | checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" | 299 | checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" |
196 | 300 | ||
197 | [[package]] | 301 | [[package]] |
302 | name = "indenter" | ||
303 | version = "0.3.3" | ||
304 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
305 | checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" | ||
306 | |||
307 | [[package]] | ||
198 | name = "indexmap" | 308 | name = "indexmap" |
199 | version = "2.5.0" | 309 | version = "2.5.0" |
200 | source = "registry+https://github.com/rust-lang/crates.io-index" | 310 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -240,6 +350,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
240 | checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" | 350 | checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" |
241 | 351 | ||
242 | [[package]] | 352 | [[package]] |
353 | name = "linux-raw-sys" | ||
354 | version = "0.4.14" | ||
355 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
356 | checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" | ||
357 | |||
358 | [[package]] | ||
243 | name = "memchr" | 359 | name = "memchr" |
244 | version = "2.7.4" | 360 | version = "2.7.4" |
245 | source = "registry+https://github.com/rust-lang/crates.io-index" | 361 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -252,6 +368,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
252 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | 368 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" |
253 | 369 | ||
254 | [[package]] | 370 | [[package]] |
371 | name = "miniz_oxide" | ||
372 | version = "0.7.4" | ||
373 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
374 | checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" | ||
375 | dependencies = [ | ||
376 | "adler", | ||
377 | ] | ||
378 | |||
379 | [[package]] | ||
255 | name = "nom" | 380 | name = "nom" |
256 | version = "7.1.3" | 381 | version = "7.1.3" |
257 | source = "registry+https://github.com/rust-lang/crates.io-index" | 382 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -262,6 +387,15 @@ dependencies = [ | |||
262 | ] | 387 | ] |
263 | 388 | ||
264 | [[package]] | 389 | [[package]] |
390 | name = "object" | ||
391 | version = "0.32.2" | ||
392 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
393 | checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" | ||
394 | dependencies = [ | ||
395 | "memchr", | ||
396 | ] | ||
397 | |||
398 | [[package]] | ||
265 | name = "once_cell" | 399 | name = "once_cell" |
266 | version = "1.19.0" | 400 | version = "1.19.0" |
267 | source = "registry+https://github.com/rust-lang/crates.io-index" | 401 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -278,6 +412,12 @@ dependencies = [ | |||
278 | ] | 412 | ] |
279 | 413 | ||
280 | [[package]] | 414 | [[package]] |
415 | name = "owo-colors" | ||
416 | version = "3.5.0" | ||
417 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
418 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | ||
419 | |||
420 | [[package]] | ||
281 | name = "pathdiff" | 421 | name = "pathdiff" |
282 | version = "0.2.1" | 422 | version = "0.2.1" |
283 | source = "registry+https://github.com/rust-lang/crates.io-index" | 423 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -329,6 +469,12 @@ dependencies = [ | |||
329 | ] | 469 | ] |
330 | 470 | ||
331 | [[package]] | 471 | [[package]] |
472 | name = "pin-project-lite" | ||
473 | version = "0.2.14" | ||
474 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
475 | checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" | ||
476 | |||
477 | [[package]] | ||
332 | name = "proc-macro2" | 478 | name = "proc-macro2" |
333 | version = "1.0.86" | 479 | version = "1.0.86" |
334 | source = "registry+https://github.com/rust-lang/crates.io-index" | 480 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -369,6 +515,25 @@ dependencies = [ | |||
369 | ] | 515 | ] |
370 | 516 | ||
371 | [[package]] | 517 | [[package]] |
518 | name = "rustc-demangle" | ||
519 | version = "0.1.24" | ||
520 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
521 | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | ||
522 | |||
523 | [[package]] | ||
524 | name = "rustix" | ||
525 | version = "0.38.36" | ||
526 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
527 | checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" | ||
528 | dependencies = [ | ||
529 | "bitflags", | ||
530 | "errno", | ||
531 | "libc", | ||
532 | "linux-raw-sys", | ||
533 | "windows-sys", | ||
534 | ] | ||
535 | |||
536 | [[package]] | ||
372 | name = "ryu" | 537 | name = "ryu" |
373 | version = "1.0.18" | 538 | version = "1.0.18" |
374 | source = "registry+https://github.com/rust-lang/crates.io-index" | 539 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -427,6 +592,21 @@ dependencies = [ | |||
427 | ] | 592 | ] |
428 | 593 | ||
429 | [[package]] | 594 | [[package]] |
595 | name = "sharded-slab" | ||
596 | version = "0.1.7" | ||
597 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
598 | checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" | ||
599 | dependencies = [ | ||
600 | "lazy_static", | ||
601 | ] | ||
602 | |||
603 | [[package]] | ||
604 | name = "shlex" | ||
605 | version = "1.3.0" | ||
606 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
607 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" | ||
608 | |||
609 | [[package]] | ||
430 | name = "syn" | 610 | name = "syn" |
431 | version = "2.0.77" | 611 | version = "2.0.77" |
432 | source = "registry+https://github.com/rust-lang/crates.io-index" | 612 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -458,6 +638,16 @@ dependencies = [ | |||
458 | ] | 638 | ] |
459 | 639 | ||
460 | [[package]] | 640 | [[package]] |
641 | name = "thread_local" | ||
642 | version = "1.1.8" | ||
643 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
644 | checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" | ||
645 | dependencies = [ | ||
646 | "cfg-if", | ||
647 | "once_cell", | ||
648 | ] | ||
649 | |||
650 | [[package]] | ||
461 | name = "tiny-keccak" | 651 | name = "tiny-keccak" |
462 | version = "2.0.2" | 652 | version = "2.0.2" |
463 | source = "registry+https://github.com/rust-lang/crates.io-index" | 653 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -501,6 +691,47 @@ dependencies = [ | |||
501 | ] | 691 | ] |
502 | 692 | ||
503 | [[package]] | 693 | [[package]] |
694 | name = "tracing" | ||
695 | version = "0.1.40" | ||
696 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
697 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" | ||
698 | dependencies = [ | ||
699 | "pin-project-lite", | ||
700 | "tracing-core", | ||
701 | ] | ||
702 | |||
703 | [[package]] | ||
704 | name = "tracing-core" | ||
705 | version = "0.1.32" | ||
706 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
707 | checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" | ||
708 | dependencies = [ | ||
709 | "once_cell", | ||
710 | "valuable", | ||
711 | ] | ||
712 | |||
713 | [[package]] | ||
714 | name = "tracing-error" | ||
715 | version = "0.2.0" | ||
716 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
717 | checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" | ||
718 | dependencies = [ | ||
719 | "tracing", | ||
720 | "tracing-subscriber", | ||
721 | ] | ||
722 | |||
723 | [[package]] | ||
724 | name = "tracing-subscriber" | ||
725 | version = "0.3.18" | ||
726 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
727 | checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" | ||
728 | dependencies = [ | ||
729 | "sharded-slab", | ||
730 | "thread_local", | ||
731 | "tracing-core", | ||
732 | ] | ||
733 | |||
734 | [[package]] | ||
504 | name = "typenum" | 735 | name = "typenum" |
505 | version = "1.17.0" | 736 | version = "1.17.0" |
506 | source = "registry+https://github.com/rust-lang/crates.io-index" | 737 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -534,6 +765,12 @@ dependencies = [ | |||
534 | ] | 765 | ] |
535 | 766 | ||
536 | [[package]] | 767 | [[package]] |
768 | name = "valuable" | ||
769 | version = "0.1.0" | ||
770 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
771 | checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" | ||
772 | |||
773 | [[package]] | ||
537 | name = "version_check" | 774 | name = "version_check" |
538 | version = "0.9.5" | 775 | version = "0.9.5" |
539 | source = "registry+https://github.com/rust-lang/crates.io-index" | 776 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -546,6 +783,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
546 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" | 783 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" |
547 | 784 | ||
548 | [[package]] | 785 | [[package]] |
786 | name = "windows-sys" | ||
787 | version = "0.52.0" | ||
788 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
789 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" | ||
790 | dependencies = [ | ||
791 | "windows-targets", | ||
792 | ] | ||
793 | |||
794 | [[package]] | ||
795 | name = "windows-targets" | ||
796 | version = "0.52.6" | ||
797 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
798 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" | ||
799 | dependencies = [ | ||
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]] | ||
811 | name = "windows_aarch64_gnullvm" | ||
812 | version = "0.52.6" | ||
813 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
814 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" | ||
815 | |||
816 | [[package]] | ||
817 | name = "windows_aarch64_msvc" | ||
818 | version = "0.52.6" | ||
819 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
820 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" | ||
821 | |||
822 | [[package]] | ||
823 | name = "windows_i686_gnu" | ||
824 | version = "0.52.6" | ||
825 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
826 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" | ||
827 | |||
828 | [[package]] | ||
829 | name = "windows_i686_gnullvm" | ||
830 | version = "0.52.6" | ||
831 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
832 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" | ||
833 | |||
834 | [[package]] | ||
835 | name = "windows_i686_msvc" | ||
836 | version = "0.52.6" | ||
837 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
838 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" | ||
839 | |||
840 | [[package]] | ||
841 | name = "windows_x86_64_gnu" | ||
842 | version = "0.52.6" | ||
843 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
844 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" | ||
845 | |||
846 | [[package]] | ||
847 | name = "windows_x86_64_gnullvm" | ||
848 | version = "0.52.6" | ||
849 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
850 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" | ||
851 | |||
852 | [[package]] | ||
853 | name = "windows_x86_64_msvc" | ||
854 | version = "0.52.6" | ||
855 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
856 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||
857 | |||
858 | [[package]] | ||
549 | name = "winnow" | 859 | name = "winnow" |
550 | version = "0.6.18" | 860 | version = "0.6.18" |
551 | source = "registry+https://github.com/rust-lang/crates.io-index" | 861 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -5,7 +5,9 @@ edition = "2021" | |||
5 | 5 | ||
6 | [dependencies] | 6 | [dependencies] |
7 | anyhow = "1.0.86" | 7 | anyhow = "1.0.86" |
8 | color-eyre = "0.6.3" | ||
8 | config = "0.14.0" | 9 | config = "0.14.0" |
10 | gethostname = "0.5.0" | ||
9 | serde = { version = "1.0.209", features = ["derive"] } | 11 | serde = { version = "1.0.209", features = ["derive"] } |
10 | serde_json = "1.0.128" | 12 | serde_json = "1.0.128" |
11 | thiserror = "1.0.63" | 13 | thiserror = "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 @@ | |||
1 | use std::time::{SystemTime, UNIX_EPOCH}; | 1 | use std::{ |
2 | fs::{create_dir_all, File, OpenOptions}, | ||
3 | io::{ErrorKind, Read, Write}, | ||
4 | path::PathBuf, | ||
5 | time::{SystemTime, UNIX_EPOCH}, | ||
6 | }; | ||
2 | 7 | ||
8 | use gethostname::gethostname; | ||
3 | use serde::{Deserialize, Serialize}; | 9 | use serde::{Deserialize, Serialize}; |
4 | use uuid::Uuid; | 10 | use uuid::Uuid; |
5 | 11 | ||
6 | use crate::{config::Config, pathinfo::PathInfo, packages::Package, error::Result}; | 12 | use crate::{ |
13 | config::Config, | ||
14 | error::{Error, Result}, | ||
15 | packages::Package, | ||
16 | pathinfo::PathInfo, | ||
17 | }; | ||
7 | 18 | ||
8 | pub type BackupId = String; | 19 | pub 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)] | ||
39 | struct BackupLocation { | 112 | struct BackupLocation { |
40 | id: BackupId, | 113 | id: BackupId, |
41 | rel_location: String, | 114 | rel_location: String, |
42 | } | 115 | } |
43 | |||
44 | type 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 @@ | |||
1 | pub type Result<T> = std::result::Result<T, Error>; | 1 | pub type Result<T> = std::result::Result<T, Error>; |
2 | 2 | ||
3 | #[derive(Debug, PartialEq, Eq, thiserror::Error)] | 3 | #[derive(Debug, thiserror::Error)] |
4 | pub enum Error { | 4 | pub 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 @@ | |||
1 | use backup::Backup; | 1 | use backup::Backup; |
2 | use config::Config; | 2 | use config::Config; |
3 | use packages::{pacman::Pacman, PackageManager}; | 3 | use packages::{pacman::Pacman, PackageManager}; |
4 | use storage::save_index; | ||
5 | 4 | ||
6 | mod backup; | 5 | mod backup; |
7 | mod config; | 6 | mod config; |
8 | mod error; | 7 | mod error; |
9 | mod pathinfo; | 8 | mod pathinfo; |
10 | mod packages; | 9 | mod packages; |
11 | mod storage; | ||
12 | 10 | ||
13 | fn main() -> anyhow::Result<()> { | 11 | fn 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)] |
154 | mod 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 @@ | |||
1 | use std::{fs::File, io::Write}; | ||
2 | |||
3 | use crate::backup::Backup; | ||
4 | |||
5 | pub 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 | } | ||