SQLite-backed Key / Value Store
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #4 from Tyrannican/rubin-integration

Rubin integration

authored by

Graham Keenan and committed by
GitHub
faa21082 0c98e295

+259 -113
+11
CHANGELOG.md
··· 1 + # Change Log 2 + 3 + Documenting changes between versions beginning from v0.3.0 4 + 5 + ## v0.3.0 6 + 7 + No breaking changes, just an update of the backend used for file creation and maintenance. 8 + Due to this allowing more extended work going forward, bumped up to v0.3.0 9 + 10 + * Changed backend file handling to use the [Rubin](https://crates.io/crates/rubin) crates instead of a custom solution 11 +
+200 -38
Cargo.lock
··· 4 4 5 5 [[package]] 6 6 name = "anstream" 7 - version = "0.3.1" 7 + version = "0.3.2" 8 8 source = "registry+https://github.com/rust-lang/crates.io-index" 9 - checksum = "6342bd4f5a1205d7f41e94a41a901f5647c938cdfa96036338e8533c9d6c2450" 9 + checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" 10 10 dependencies = [ 11 11 "anstyle", 12 12 "anstyle-parse", ··· 63 63 ] 64 64 65 65 [[package]] 66 + name = "autocfg" 67 + version = "1.1.0" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 70 + 71 + [[package]] 66 72 name = "bitflags" 67 73 version = "1.3.2" 68 74 source = "registry+https://github.com/rust-lang/crates.io-index" 69 75 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 70 76 71 77 [[package]] 78 + name = "bytes" 79 + version = "1.4.0" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" 82 + 83 + [[package]] 72 84 name = "cc" 73 85 version = "1.0.79" 74 86 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 82 94 83 95 [[package]] 84 96 name = "clap" 85 - version = "4.2.5" 97 + version = "4.3.1" 86 98 source = "registry+https://github.com/rust-lang/crates.io-index" 87 - checksum = "8a1f23fa97e1d1641371b51f35535cb26959b8e27ab50d167a8b996b5bada819" 99 + checksum = "b4ed2379f8603fa2b7509891660e802b88c70a79a6427a70abb5968054de2c28" 88 100 dependencies = [ 89 101 "clap_builder", 90 102 "clap_derive", ··· 93 105 94 106 [[package]] 95 107 name = "clap_builder" 96 - version = "4.2.5" 108 + version = "4.3.1" 97 109 source = "registry+https://github.com/rust-lang/crates.io-index" 98 - checksum = "0fdc5d93c358224b4d6867ef1356d740de2303e9892edc06c5340daeccd96bab" 110 + checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" 99 111 dependencies = [ 100 112 "anstream", 101 113 "anstyle", ··· 106 118 107 119 [[package]] 108 120 name = "clap_derive" 109 - version = "4.2.0" 121 + version = "4.3.1" 110 122 source = "registry+https://github.com/rust-lang/crates.io-index" 111 - checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" 123 + checksum = "59e9ef9a08ee1c0e1f2e162121665ac45ac3783b0f897db7244ae75ad9a8f65b" 112 124 dependencies = [ 113 125 "heck", 114 126 "proc-macro2", ··· 118 130 119 131 [[package]] 120 132 name = "clap_lex" 121 - version = "0.4.1" 133 + version = "0.5.0" 122 134 source = "registry+https://github.com/rust-lang/crates.io-index" 123 - checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" 135 + checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" 124 136 125 137 [[package]] 126 138 name = "colorchoice" ··· 141 153 142 154 [[package]] 143 155 name = "dirs" 144 - version = "5.0.0" 156 + version = "5.0.1" 145 157 source = "registry+https://github.com/rust-lang/crates.io-index" 146 - checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd" 158 + checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" 147 159 dependencies = [ 148 160 "dirs-sys", 149 161 ] 150 162 151 163 [[package]] 152 164 name = "dirs-sys" 153 - version = "0.4.0" 165 + version = "0.4.1" 154 166 source = "registry+https://github.com/rust-lang/crates.io-index" 155 - checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b" 167 + checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" 156 168 dependencies = [ 157 169 "libc", 170 + "option-ext", 158 171 "redox_users", 159 - "windows-sys 0.45.0", 172 + "windows-sys 0.48.0", 160 173 ] 161 174 162 175 [[package]] ··· 208 221 209 222 [[package]] 210 223 name = "hermit-abi" 224 + version = "0.2.6" 225 + source = "registry+https://github.com/rust-lang/crates.io-index" 226 + checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" 227 + dependencies = [ 228 + "libc", 229 + ] 230 + 231 + [[package]] 232 + name = "hermit-abi" 211 233 version = "0.3.1" 212 234 source = "registry+https://github.com/rust-lang/crates.io-index" 213 235 checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" 214 236 215 237 [[package]] 216 238 name = "io-lifetimes" 217 - version = "1.0.10" 239 + version = "1.0.11" 218 240 source = "registry+https://github.com/rust-lang/crates.io-index" 219 - checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" 241 + checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" 220 242 dependencies = [ 221 243 "hermit-abi 0.3.1", 222 244 "libc", ··· 249 271 250 272 [[package]] 251 273 name = "libc" 252 - version = "0.2.142" 274 + version = "0.2.144" 253 275 source = "registry+https://github.com/rust-lang/crates.io-index" 254 - checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" 276 + checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" 255 277 256 278 [[package]] 257 279 name = "linux-raw-sys" 258 - version = "0.3.6" 280 + version = "0.3.8" 281 + source = "registry+https://github.com/rust-lang/crates.io-index" 282 + checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" 283 + 284 + [[package]] 285 + name = "lock_api" 286 + version = "0.4.9" 259 287 source = "registry+https://github.com/rust-lang/crates.io-index" 260 - checksum = "b64f40e5e03e0d54f03845c8197d0291253cdbedfb1cb46b13c2c117554a9f4c" 288 + checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" 289 + dependencies = [ 290 + "autocfg", 291 + "scopeguard", 292 + ] 293 + 294 + [[package]] 295 + name = "mio" 296 + version = "0.8.8" 297 + source = "registry+https://github.com/rust-lang/crates.io-index" 298 + checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" 299 + dependencies = [ 300 + "libc", 301 + "wasi", 302 + "windows-sys 0.48.0", 303 + ] 304 + 305 + [[package]] 306 + name = "num_cpus" 307 + version = "1.15.0" 308 + source = "registry+https://github.com/rust-lang/crates.io-index" 309 + checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" 310 + dependencies = [ 311 + "hermit-abi 0.2.6", 312 + "libc", 313 + ] 261 314 262 315 [[package]] 263 316 name = "once_cell" 264 - version = "1.17.1" 317 + version = "1.17.2" 318 + source = "registry+https://github.com/rust-lang/crates.io-index" 319 + checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" 320 + 321 + [[package]] 322 + name = "option-ext" 323 + version = "0.2.0" 324 + source = "registry+https://github.com/rust-lang/crates.io-index" 325 + checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" 326 + 327 + [[package]] 328 + name = "parking_lot" 329 + version = "0.12.1" 265 330 source = "registry+https://github.com/rust-lang/crates.io-index" 266 - checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" 331 + checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 332 + dependencies = [ 333 + "lock_api", 334 + "parking_lot_core", 335 + ] 336 + 337 + [[package]] 338 + name = "parking_lot_core" 339 + version = "0.9.7" 340 + source = "registry+https://github.com/rust-lang/crates.io-index" 341 + checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" 342 + dependencies = [ 343 + "cfg-if", 344 + "libc", 345 + "redox_syscall", 346 + "smallvec", 347 + "windows-sys 0.45.0", 348 + ] 349 + 350 + [[package]] 351 + name = "pin-project-lite" 352 + version = "0.2.9" 353 + source = "registry+https://github.com/rust-lang/crates.io-index" 354 + checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 267 355 268 356 [[package]] 269 357 name = "proc-macro2" 270 - version = "1.0.56" 358 + version = "1.0.59" 271 359 source = "registry+https://github.com/rust-lang/crates.io-index" 272 - checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" 360 + checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" 273 361 dependencies = [ 274 362 "unicode-ident", 275 363 ] 276 364 277 365 [[package]] 278 366 name = "quote" 279 - version = "1.0.26" 367 + version = "1.0.28" 280 368 source = "registry+https://github.com/rust-lang/crates.io-index" 281 - checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" 369 + checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" 282 370 dependencies = [ 283 371 "proc-macro2", 284 372 ] ··· 304 392 ] 305 393 306 394 [[package]] 395 + name = "rubin" 396 + version = "0.2.0" 397 + source = "registry+https://github.com/rust-lang/crates.io-index" 398 + checksum = "a4cd8089e004cd9c021660c698720326fcbab770a13df50d16eb907b89327727" 399 + dependencies = [ 400 + "serde", 401 + "serde_json", 402 + "tokio", 403 + ] 404 + 405 + [[package]] 307 406 name = "rustix" 308 - version = "0.37.15" 407 + version = "0.37.19" 309 408 source = "registry+https://github.com/rust-lang/crates.io-index" 310 - checksum = "a0661814f891c57c930a610266415528da53c4933e6dea5fb350cbfe048a9ece" 409 + checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" 311 410 dependencies = [ 312 411 "bitflags", 313 412 "errno", ··· 325 424 326 425 [[package]] 327 426 name = "safir" 328 - version = "0.2.1" 427 + version = "0.3.0" 329 428 dependencies = [ 330 429 "clap", 331 430 "colored", 332 431 "dirs", 432 + "rubin", 333 433 "serde", 334 434 "serde_json", 435 + "tokio", 335 436 ] 336 437 337 438 [[package]] 439 + name = "scopeguard" 440 + version = "1.1.0" 441 + source = "registry+https://github.com/rust-lang/crates.io-index" 442 + checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 443 + 444 + [[package]] 338 445 name = "serde" 339 - version = "1.0.160" 446 + version = "1.0.163" 340 447 source = "registry+https://github.com/rust-lang/crates.io-index" 341 - checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" 448 + checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" 342 449 dependencies = [ 343 450 "serde_derive", 344 451 ] 345 452 346 453 [[package]] 347 454 name = "serde_derive" 348 - version = "1.0.160" 455 + version = "1.0.163" 349 456 source = "registry+https://github.com/rust-lang/crates.io-index" 350 - checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" 457 + checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" 351 458 dependencies = [ 352 459 "proc-macro2", 353 460 "quote", ··· 366 473 ] 367 474 368 475 [[package]] 476 + name = "signal-hook-registry" 477 + version = "1.4.1" 478 + source = "registry+https://github.com/rust-lang/crates.io-index" 479 + checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" 480 + dependencies = [ 481 + "libc", 482 + ] 483 + 484 + [[package]] 485 + name = "smallvec" 486 + version = "1.10.0" 487 + source = "registry+https://github.com/rust-lang/crates.io-index" 488 + checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 489 + 490 + [[package]] 491 + name = "socket2" 492 + version = "0.4.9" 493 + source = "registry+https://github.com/rust-lang/crates.io-index" 494 + checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" 495 + dependencies = [ 496 + "libc", 497 + "winapi", 498 + ] 499 + 500 + [[package]] 369 501 name = "strsim" 370 502 version = "0.10.0" 371 503 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 373 505 374 506 [[package]] 375 507 name = "syn" 376 - version = "2.0.15" 508 + version = "2.0.18" 377 509 source = "registry+https://github.com/rust-lang/crates.io-index" 378 - checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" 510 + checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" 379 511 dependencies = [ 380 512 "proc-macro2", 381 513 "quote", ··· 403 535 ] 404 536 405 537 [[package]] 538 + name = "tokio" 539 + version = "1.28.2" 540 + source = "registry+https://github.com/rust-lang/crates.io-index" 541 + checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" 542 + dependencies = [ 543 + "autocfg", 544 + "bytes", 545 + "libc", 546 + "mio", 547 + "num_cpus", 548 + "parking_lot", 549 + "pin-project-lite", 550 + "signal-hook-registry", 551 + "socket2", 552 + "tokio-macros", 553 + "windows-sys 0.48.0", 554 + ] 555 + 556 + [[package]] 557 + name = "tokio-macros" 558 + version = "2.1.0" 559 + source = "registry+https://github.com/rust-lang/crates.io-index" 560 + checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" 561 + dependencies = [ 562 + "proc-macro2", 563 + "quote", 564 + "syn", 565 + ] 566 + 567 + [[package]] 406 568 name = "unicode-ident" 407 - version = "1.0.8" 569 + version = "1.0.9" 408 570 source = "registry+https://github.com/rust-lang/crates.io-index" 409 - checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" 571 + checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" 410 572 411 573 [[package]] 412 574 name = "utf8parse"
+3 -1
Cargo.toml
··· 1 1 [package] 2 2 name = "safir" 3 - version = "0.2.1" 3 + version = "0.3.0" 4 4 edition = "2021" 5 5 authors = ["Graham Keenan graham.keenan@outlook.com"] 6 6 license = "MIT OR Apache-2.0" ··· 19 19 serde_json = "1" 20 20 dirs = "5" 21 21 colored = "2" 22 + rubin = "0.2.0" 23 + tokio = { version = "1.28.2", features = ["full"] }
+11 -7
src/main.rs
··· 2 2 mod safir; 3 3 4 4 use cli::*; 5 - use safir::Safir; 6 5 7 - fn main() -> std::io::Result<()> { 6 + #[tokio::main] 7 + async fn main() -> std::io::Result<()> { 8 8 let cli = Cli::parse(); 9 - let mut safir = Safir::init()?; 9 + let mut safir = safir::Safir::init().await?; 10 10 11 11 match &cli.command { 12 12 Commands::Add(args) => { 13 - safir.add_entry(args.key.clone(), args.value.clone()); 13 + safir 14 + .add_entry(args.key.clone(), args.value.clone()) 15 + .await?; 14 16 } 15 17 Commands::Get(args) => { 16 18 if let Some(key) = &args.key { 17 - safir.get_entry(key.clone()); 19 + safir.get_entry(key.clone())?; 18 20 } else { 19 21 safir.display_all(); 20 22 } 21 23 } 22 24 Commands::Rm(args) => { 23 - safir.remove_entry(args.key.clone()); 25 + safir.remove_entry(args.key.clone()).await?; 24 26 } 25 27 Commands::Alias(args) => { 26 28 safir.set_commands("alias", &args.keys); ··· 28 30 Commands::Export(args) => { 29 31 safir.set_commands("export", &args.keys); 30 32 } 31 - Commands::Clear => safir.clear_entries(), 33 + Commands::Clear => { 34 + safir.clear_entries().await?; 35 + } 32 36 Commands::Purge => safir.purge(), 33 37 } 34 38 Ok(())
+34 -67
src/safir.rs
··· 8 8 //! 9 9 //! Safir gives you the option to add / get / remove items from the store 10 10 //! and to clear / purge when you're finished with them. 11 - use std::{ 12 - collections::HashMap, 13 - fs::{File, OpenOptions}, 14 - io::{BufWriter, Read, Result, Write}, 15 - path::PathBuf, 16 - }; 11 + use std::io::{Result, Write}; 17 12 18 13 use colored::*; 14 + 15 + use rubin::store::persistence::PersistentStore; 19 16 20 17 /// Formats and prints the message to stdout 21 18 fn print_output(msg: &str) { ··· 28 25 } 29 26 30 27 /// Safir Store (fancy wrapper around reading and writing to a JSON file) 31 - #[derive(Default)] 32 28 pub struct Safir { 33 - pub path: PathBuf, 34 - pub store: HashMap<String, String>, 29 + pub store: PersistentStore, 35 30 } 36 31 37 32 impl Safir { 38 33 /// Initialises the Safirstore if not already initialised 39 - pub fn init() -> Result<Self> { 40 - let mut safir = Self::default(); 41 - if let Some(home_dir) = dirs::home_dir() { 42 - let safir_path = home_dir.join(".safirstore"); 43 - std::fs::create_dir_all(&safir_path)?; 44 - safir.path = safir_path.join("safirstore.json"); 45 - safir.load()?; 46 - } 34 + pub async fn init() -> Result<Self> { 35 + let home_dir = dirs::home_dir().unwrap(); 36 + let store_path = home_dir.join(".safirstore/safirstore.json"); 37 + let mut ps = if store_path.exists() { 38 + PersistentStore::from_existing(store_path).await? 39 + } else { 40 + PersistentStore::new(store_path).await? 41 + }; 47 42 48 - Ok(safir) 43 + ps.set_write_on_update(true); 44 + Ok(Self { store: ps }) 49 45 } 50 46 51 47 /// Add an entry to the store and write it out to disk 52 - pub fn add_entry(&mut self, key: String, value: String) { 53 - self.store 54 - .entry(key) 55 - .and_modify(|entry| *entry = value.clone()) 56 - .or_insert(value); 57 - 58 - self.write().expect("unable to write store out to file!"); 48 + pub async fn add_entry(&mut self, key: String, value: String) -> Result<String> { 49 + self.store.insert_string(&key, &value).await 59 50 } 60 51 61 52 /// Get an entry form the store by loading it from disk and displaying it 62 - pub fn get_entry(&self, key: String) { 53 + pub fn get_entry(&self, key: String) -> Result<()> { 63 54 print_header(); 64 - let output = if let Some(val) = self.store.get(&key) { 55 + let output = if let Ok(val) = self.store.get_string(&key) { 65 56 format!("{}: \"{}\"", key.bold().yellow(), val) 66 57 } else { 67 58 format!("{}: ", key.bold().yellow()) 68 59 }; 69 60 70 61 print_output(&output); 62 + 63 + Ok(()) 71 64 } 72 65 73 66 /// Display all key/values in the store 74 67 pub fn display_all(&self) { 75 68 print_header(); 76 69 let mut output: String; 77 - for (key, value) in self.store.iter() { 70 + let strings = self.store.get_string_store_ref(); 71 + for (key, value) in strings.iter() { 78 72 output = format!("{}: \"{}\"", key.bold().yellow(), value); 79 73 print_output(&output); 80 74 } 81 75 } 82 76 83 77 /// Remove a key/value pair from the store and update onto disk 84 - pub fn remove_entry(&mut self, keys: Vec<String>) { 78 + pub async fn remove_entry(&mut self, keys: Vec<String>) -> Result<()> { 85 79 for key in &keys { 86 - self.store.remove_entry(key); 80 + self.store.remove_string(key).await?; 87 81 } 88 - self.write().expect("unable to update safirstore"); 82 + 83 + Ok(()) 89 84 } 90 85 91 86 /// Outputs the key/value pair as a command with the prefix ··· 101 96 }; 102 97 103 98 for key in keys { 104 - if let Some(value) = self.store.get(key) { 99 + if let Ok(value) = self.store.get_string(key) { 105 100 println!("{} {}=\"{}\"\n", prefix, key.bold().yellow(), value); 106 101 } 107 102 } 108 103 } 109 104 110 105 /// Clear the the contents of the store and update onto disk 111 - pub fn clear_entries(&mut self) { 106 + pub async fn clear_entries(&mut self) -> Result<()> { 112 107 if self.confirm_entry("Are you sure you want to clear the store?") { 113 - self.store.clear(); 114 - self.write().expect("unable to clear safirstore"); 108 + self.store.clear_strings().await?; 115 109 } 110 + 111 + Ok(()) 116 112 } 117 113 118 - /// Remove the `.safirstore` directory and all contents 114 + /// Remove the store directory and all contents 119 115 pub fn purge(&mut self) { 120 116 if self.confirm_entry("Are you sure you want to purge Safirstore?") { 121 - self.path.pop(); 122 - std::fs::remove_dir_all(&self.path).expect("unable to remove safirstore directory"); 117 + std::fs::remove_dir_all(&self.store.path) 118 + .expect("unable to remove safirstore directory"); 123 119 } 124 120 } 125 121 ··· 139 135 } 140 136 141 137 false 142 - } 143 - 144 - /// Load the contents of the store off of disk 145 - fn load(&mut self) -> Result<()> { 146 - let mut f = OpenOptions::new() 147 - .create(true) 148 - .read(true) 149 - .write(true) 150 - .open(&self.path)?; 151 - 152 - let mut contents = String::new(); 153 - f.read_to_string(&mut contents)?; 154 - if !contents.is_empty() { 155 - let store = serde_json::from_str(&contents)?; 156 - self.store = store; 157 - } else { 158 - self.write()?; 159 - } 160 - 161 - Ok(()) 162 - } 163 - 164 - /// Write the contents of the store out to disk in the .safirstore/ directory 165 - fn write(&self) -> Result<()> { 166 - let mut writer = BufWriter::new(File::create(&self.path)?); 167 - serde_json::to_writer_pretty(&mut writer, &self.store)?; 168 - writer.write_all(b"\n")?; 169 - writer.flush()?; 170 - Ok(()) 171 138 } 172 139 }