update dependencies

This commit is contained in:
Cyryl Płotnicki 2023-11-04 09:05:12 +00:00
parent 50d7df08be
commit bd5217bbd4
9 changed files with 529 additions and 376 deletions

811
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -3,20 +3,19 @@ name = "bakare"
version = "0.1.0" version = "0.1.0"
authors = ["Cyryl Płotnicki <cyplo@cyplo.dev>"] authors = ["Cyryl Płotnicki <cyplo@cyplo.dev>"]
edition = "2021" edition = "2021"
rust-version = "1.56" rust-version = "1.63"
license = "AGPL-3.0" license = "AGPL-3.0"
description = "modern and simple, yet efficient backup solution" description = "modern and simple, yet efficient backup solution"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
base64 = "0.13" base64 = "0.21"
blake = "2" blake = "2"
chacha20poly1305 = "0.9" chacha20poly1305 = "0.10"
fail = "0.5" fail = "0.5"
femme = "2" femme = "2"
hex = "0.4" hex = "0.4"
log = "0.4" log = "0.4"
nix = "0.24"
rand = "0.8" rand = "0.8"
reed-solomon = "0.2" reed-solomon = "0.2"
seahorse = "2" seahorse = "2"
@ -27,8 +26,13 @@ tempfile = "3"
uuid = { version = "1", features = ["v4"] } uuid = { version = "1", features = ["v4"] }
walkdir = "2" walkdir = "2"
[dependencies.nix]
version = "0.27"
default-features = false
features = ["process"]
[dev-dependencies] [dev-dependencies]
criterion = "0.3" criterion = "0.5"
pretty_assertions = "1" pretty_assertions = "1"
proptest = "1" proptest = "1"
two-rusty-forks = "0.4" two-rusty-forks = "0.4"

View file

@ -3,11 +3,11 @@
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1650374568, "lastModified": 1696426674,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra", "owner": "edolstra",
"repo": "flake-compat", "repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8", "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -21,11 +21,11 @@
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1655042882, "lastModified": 1698420672,
"narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=", "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"owner": "nix-community", "owner": "nix-community",
"repo": "naersk", "repo": "naersk",
"rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f", "rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -36,11 +36,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1658119717, "lastModified": 1699065553,
"narHash": "sha256-4upOZIQQ7Bc4CprqnHsKnqYfw+arJeAuU+QcpjYBXW0=", "narHash": "sha256-j8UmH8fqXcOgL6WrlMcvV2m2XQ6OzU0IBucyuJ0vnyQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9eb60f25aff0d2218c848dd4574a0ab5e296cabe", "rev": "8ab9c53eee434651ce170dee1d9727b974e9a6b6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -50,11 +50,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1658119717, "lastModified": 1699065553,
"narHash": "sha256-4upOZIQQ7Bc4CprqnHsKnqYfw+arJeAuU+QcpjYBXW0=", "narHash": "sha256-j8UmH8fqXcOgL6WrlMcvV2m2XQ6OzU0IBucyuJ0vnyQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9eb60f25aff0d2218c848dd4574a0ab5e296cabe", "rev": "8ab9c53eee434651ce170dee1d9727b974e9a6b6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -70,13 +70,31 @@
"utils": "utils" "utils": "utils"
} }
}, },
"utils": { "systems": {
"locked": { "locked": {
"lastModified": 1656928814, "lastModified": 1681028828,
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -6,9 +6,8 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use chacha20poly1305::aead::{Aead, NewAead}; use chacha20poly1305::{aead::Aead, Key, KeyInit, XChaCha20Poly1305, XNonce};
use chacha20poly1305::{Key, XChaCha20Poly1305, XNonce}; // Or `XChaCha20Poly1305` use nix::unistd::getpid;
use uuid::Uuid; use uuid::Uuid;
use crate::index::item::IndexItem; use crate::index::item::IndexItem;
@ -18,7 +17,6 @@ use crate::repository::ItemId;
use anyhow::Result; use anyhow::Result;
use anyhow::*; use anyhow::*;
use lock::Lock; use lock::Lock;
use nix::unistd::getpid;
use std::{cmp::max, io::Write}; use std::{cmp::max, io::Write};
impl Index { impl Index {

View file

@ -103,7 +103,7 @@ impl Lock {
fn lock_file_path(path: &Path, lock_id: Uuid) -> Result<PathBuf> { fn lock_file_path(path: &Path, lock_id: Uuid) -> Result<PathBuf> {
let file_name = format!("{}{}", lock_id, FILE_EXTENSION); let file_name = format!("{}{}", lock_id, FILE_EXTENSION);
Ok(path.join(&file_name)) Ok(path.join(file_name))
} }
} }

View file

@ -39,7 +39,7 @@ impl RepositoryItem {
let original_source_path = Path::new(self.original_source_path()); let original_source_path = Path::new(self.original_source_path());
let source_path_relative = original_source_path.strip_prefix("/")?; let source_path_relative = original_source_path.strip_prefix("/")?;
let target_path = save_to.join(&source_path_relative); let target_path = save_to.join(source_path_relative);
let parent = target_path let parent = target_path
.parent() .parent()
.ok_or_else(|| anyhow!("cannot compute parent path for {}", &target_path.to_string_lossy()))?; .ok_or_else(|| anyhow!("cannot compute parent path for {}", &target_path.to_string_lossy()))?;

View file

@ -43,13 +43,15 @@ pub struct RepositoryItemIterator<'a> {
//TODO: move to serializers::base64 //TODO: move to serializers::base64
mod base64 { mod base64 {
use ::base64; use ::base64;
use base64::{engine::general_purpose, Engine};
use serde::{de, Deserialize, Deserializer, Serializer}; use serde::{de, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_str(&base64::encode(bytes)) let encoded = general_purpose::STANDARD.encode(bytes);
serializer.serialize_str(&encoded)
} }
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error> pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
@ -57,7 +59,7 @@ mod base64 {
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let s = <&str>::deserialize(deserializer)?; let s = <&str>::deserialize(deserializer)?;
base64::decode(s).map_err(de::Error::custom) general_purpose::STANDARD.decode(s).map_err(de::Error::custom)
} }
} }
@ -97,7 +99,7 @@ impl Debug for ItemId {
} }
} }
impl<'a> Repository { impl Repository {
pub fn init(path: &Path, secret: &str) -> Result<Repository> { pub fn init(path: &Path, secret: &str) -> Result<Repository> {
fs::create_dir_all(path)?; fs::create_dir_all(path)?;
let mut index = Index::new()?; let mut index = Index::new()?;
@ -129,7 +131,7 @@ impl<'a> Repository {
pub fn store(&mut self, source_path: &Path) -> Result<()> { pub fn store(&mut self, source_path: &Path) -> Result<()> {
let id = Repository::calculate_id(source_path)?; let id = Repository::calculate_id(source_path)?;
let destination = self.data_dir()?; let destination = self.data_dir()?;
let destination = destination.join(&id.to_string()); let destination = destination.join(id.to_string());
if !source_path.metadata()?.is_file() { if !source_path.metadata()?.is_file() {
return Ok(()); return Ok(());
@ -139,9 +141,9 @@ impl<'a> Repository {
.ok_or_else(|| anyhow!("cannot compute parent path for {}", &destination.to_string_lossy()))?; .ok_or_else(|| anyhow!("cannot compute parent path for {}", &destination.to_string_lossy()))?;
fs::create_dir_all(parent)?; fs::create_dir_all(parent)?;
if !destination.exists() { if !destination.exists() {
fs::copy(&source_path, &destination)?; fs::copy(source_path, &destination)?;
} }
let relative_path = destination.strip_prefix(&self.path())?; let relative_path = destination.strip_prefix(self.path())?;
self.index.remember(source_path, &relative_path.to_string_lossy(), id); self.index.remember(source_path, &relative_path.to_string_lossy(), id);
Ok(()) Ok(())
} }

View file

@ -50,7 +50,7 @@ pub mod in_memory {
restore_engine.restore(&item.unwrap())?; restore_engine.restore(&item.unwrap())?;
let source_file_relative_path = Path::new(source_file_full_path).strip_prefix("/")?; let source_file_relative_path = Path::new(source_file_full_path).strip_prefix("/")?;
let restored_file_path = restore_target.path().join(&source_file_relative_path); let restored_file_path = restore_target.path().join(source_file_relative_path);
assert_target_file_contents(&restored_file_path, contents) assert_target_file_contents(&restored_file_path, contents)
} }
@ -67,7 +67,7 @@ pub mod in_memory {
let restore_engine = restore::Engine::new(&mut restore_repository, restore_target.path())?; let restore_engine = restore::Engine::new(&mut restore_repository, restore_target.path())?;
restore_engine.restore(&old_item.unwrap())?; restore_engine.restore(&old_item.unwrap())?;
let source_file_relative_path = Path::new(source_file_full_path).strip_prefix("/")?; let source_file_relative_path = Path::new(source_file_full_path).strip_prefix("/")?;
let restored_file_path = restore_target.path().join(&source_file_relative_path); let restored_file_path = restore_target.path().join(source_file_relative_path);
assert_target_file_contents(&restored_file_path, old_contents) assert_target_file_contents(&restored_file_path, old_contents)
} }

View file

@ -22,7 +22,7 @@ mod must {
let dir = tempdir()?; let dir = tempdir()?;
let repository_path = dir.path(); let repository_path = dir.path();
let repository_path = repository_path.join(&format!("repository-{}", getpid())); let repository_path = repository_path.join(format!("repository-{}", getpid()));
let secret = "some secret"; let secret = "some secret";
Repository::init(&repository_path, secret)?; Repository::init(&repository_path, secret)?;