chore: rustfmt the workspace and make clippy -D warnings pass

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:19:21 +07:00
parent d7fe99edd7
commit f13f0e6953
46 changed files with 6606 additions and 1496 deletions

View File

@@ -43,7 +43,7 @@ impl VaultKey {
if let Some(parent) = salt_path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(salt_path, &salt)?;
fs::write(salt_path, salt)?;
restrict_secret_file(salt_path)?;
let spec = KdfSpec::argon2id();
fs::write(&marker, serde_json::to_vec_pretty(&spec)?)?;

View File

@@ -14,7 +14,8 @@ use tessera_core::decay::{
use tessera_core::manifest::SnapshotManifest;
use uuid::Uuid;
const RESTIC_CONFIG: &str = "{\n \"version\": 2,\n \"id\": \"tessera-restic-layout-v1\",\n \"tessera\": true\n}\n";
const RESTIC_CONFIG: &str =
"{\n \"version\": 2,\n \"id\": \"tessera-restic-layout-v1\",\n \"tessera\": true\n}\n";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StoredSnapshot {
@@ -173,11 +174,15 @@ impl Vault {
restic_id: &str,
) -> Result<StoredSnapshot> {
let config = self.outpost_config(manifest.orbit_id)?;
anyhow::ensure!(config.outpost_id == outpost_id, "repository belongs to another outpost");
anyhow::ensure!(
config.outpost_id == outpost_id,
"repository belongs to another outpost"
);
let repo = self.outpost_repository(manifest.orbit_id, config);
let id = manifest.snapshot_id;
let expected_path = (manifest.provider != "filesystem").then_some(restic::PAYLOAD);
let summary = repo.snapshot_summary(restic_id, Some(&restic::tessera_tag(id)), expected_path)?;
let summary =
repo.snapshot_summary(restic_id, Some(&restic::tessera_tag(id)), expected_path)?;
Ok(StoredSnapshot {
id,
taken_at: Utc::now(),
@@ -310,7 +315,13 @@ impl Vault {
repo.init()
.context("opening the deduplicated vault (restic must be on PATH)")?;
let mut cmd = repo.command();
cmd.args(["backup", "--json", "--quiet", "--tag", &restic::tessera_tag(manifest.snapshot_id)]);
cmd.args([
"backup",
"--json",
"--quiet",
"--tag",
&restic::tessera_tag(manifest.snapshot_id),
]);
if dry_run {
cmd.arg("--dry-run");
}
@@ -339,7 +350,10 @@ impl Vault {
}
pub fn import_legacy_payload(
&self, manifest: SnapshotManifest, payload: File, taken_at: chrono::DateTime<Utc>,
&self,
manifest: SnapshotManifest,
payload: File,
taken_at: chrono::DateTime<Utc>,
) -> Result<bool> {
let id = manifest.snapshot_id;
let receipts = self.root.join("keys/legacy-imports");
@@ -351,7 +365,8 @@ impl Vault {
}
let snapshots = self.root.join("snapshots");
let already_imported = || -> Result<bool> {
Ok(self.has_published_snapshot(id)? || snapshots.join(format!("{id}.expired")).try_exists()?)
Ok(self.has_published_snapshot(id)?
|| snapshots.join(format!("{id}.expired")).try_exists()?)
};
let imported = if already_imported()? {
false
@@ -378,18 +393,32 @@ impl Vault {
}
pub fn legacy_import_exists(&self, id: Uuid) -> Result<bool> {
Ok(self.root.join("keys/legacy-imports").join(id.to_string()).try_exists()?)
Ok(self
.root
.join("keys/legacy-imports")
.join(id.to_string())
.try_exists()?)
}
pub fn verify_prepared_payload(&self, snap: &StoredSnapshot, expected: &[u8; 32]) -> Result<()> {
pub fn verify_prepared_payload(
&self,
snap: &StoredSnapshot,
expected: &[u8; 32],
) -> Result<()> {
use sha2::{Digest, Sha256};
let id = snap.tree_root.strip_prefix(restic::PREFIX).context("prepared payload is missing")?;
let id = snap
.tree_root
.strip_prefix(restic::PREFIX)
.context("prepared payload is missing")?;
let mut file = tempfile::tempfile()?;
self.restic.dump(id, restic::PAYLOAD, file.try_clone()?)?;
file.seek(SeekFrom::Start(0))?;
let mut digest = Sha256::new();
std::io::copy(&mut file, &mut digest)?;
anyhow::ensure!(digest.finalize()[..] == expected[..], "stored payload checksum mismatch");
anyhow::ensure!(
digest.finalize()[..] == expected[..],
"stored payload checksum mismatch"
);
Ok(())
}
@@ -405,7 +434,11 @@ impl Vault {
}
pub fn has_published_snapshot(&self, id: Uuid) -> Result<bool> {
Ok(self.root.join("snapshots").join(format!("{id}.json.enc")).try_exists()?)
Ok(self
.root
.join("snapshots")
.join(format!("{id}.json.enc"))
.try_exists()?)
}
fn index_path(&self) -> PathBuf {
@@ -552,15 +585,33 @@ impl Vault {
}
pub fn prepare_offsite_copy(&self, id: Uuid) -> Result<crate::OffsiteCopy> {
let snapshot = self.read_snapshot_file(&self.root.join("snapshots").join(format!("{id}.json.enc")))?;
anyhow::ensure!(snapshot.manifest.restore_hints.get("job_id").is_some(), "snapshot is not a capture job");
let (source, restic_id) = if let Some(id) = snapshot.tree_root.strip_prefix(restic::OUTPOST_PREFIX) {
let orbit = snapshot.manifest.orbit_id;
(self.outpost_repository(orbit, self.outpost_config(orbit)?), id)
} else {
(self.restic.clone(), snapshot.tree_root.strip_prefix(restic::PREFIX).context("capture Restic snapshot missing")?)
};
Ok(crate::OffsiteCopy { snapshot: id, source, restic_id: restic_id.to_owned() })
let snapshot =
self.read_snapshot_file(&self.root.join("snapshots").join(format!("{id}.json.enc")))?;
anyhow::ensure!(
snapshot.manifest.restore_hints.get("job_id").is_some(),
"snapshot is not a capture job"
);
let (source, restic_id) =
if let Some(id) = snapshot.tree_root.strip_prefix(restic::OUTPOST_PREFIX) {
let orbit = snapshot.manifest.orbit_id;
(
self.outpost_repository(orbit, self.outpost_config(orbit)?),
id,
)
} else {
(
self.restic.clone(),
snapshot
.tree_root
.strip_prefix(restic::PREFIX)
.context("capture Restic snapshot missing")?,
)
};
Ok(crate::OffsiteCopy {
snapshot: id,
source,
restic_id: restic_id.to_owned(),
})
}
pub fn get_snapshot(&self, id: Uuid) -> Result<Option<StoredSnapshot>> {
@@ -574,7 +625,9 @@ impl Vault {
}
pub fn restore_snapshot(&self, id: Uuid, dest: &Path) -> Result<u64> {
let snap = self.get_snapshot(id)?.context("snapshot metadata not found")?;
let snap = self
.get_snapshot(id)?
.context("snapshot metadata not found")?;
let parent = dest
.parent()
.filter(|p| !p.as_os_str().is_empty())
@@ -583,7 +636,11 @@ impl Vault {
let mut temp = tempfile::NamedTempFile::new_in(parent)?;
if let Some(id) = snap.tree_root.strip_prefix(restic::OUTPOST_PREFIX) {
let orbit_id = snap.manifest.orbit_id;
let path = if snap.manifest.restore_hints["format"] == "tar" { "/" } else { restic::PAYLOAD };
let path = if snap.manifest.restore_hints["format"] == "tar" {
"/"
} else {
restic::PAYLOAD
};
self.outpost_repository(orbit_id, self.outpost_config(orbit_id)?)
.dump(id, path, temp.reopen()?)?;
} else if let Some(id) = snap.tree_root.strip_prefix(restic::PREFIX) {
@@ -682,9 +739,14 @@ impl Vault {
pub fn prune_with_decay(&mut self, preset: &str) -> Result<Vec<Uuid>> {
let snaps = self.list_snapshots()?;
self.prune_snapshots(preset, None, snaps.into_iter()
.filter(|snapshot| snapshot.manifest.provider != "legacy-history"
&& snapshot.manifest.restore_hints.get("job_id").is_none()))
self.prune_snapshots(
preset,
None,
snaps.into_iter().filter(|snapshot| {
snapshot.manifest.provider != "legacy-history"
&& snapshot.manifest.restore_hints.get("job_id").is_none()
}),
)
}
pub fn prune_orbit_with_decay(
@@ -829,9 +891,7 @@ mod tests {
paths: vec![],
restore_hints: serde_json::json!({}),
};
let snap = vault
.snapshot(manifest, b"payload bytes", false)
.unwrap();
let snap = vault.snapshot(manifest, b"payload bytes", false).unwrap();
let list = vault.list_snapshots().unwrap();
assert_eq!(list.len(), 1);
assert_eq!(list[0].id, snap.id);
@@ -918,7 +978,9 @@ mod tests {
new_data_chunks: None,
};
fs::write(
dir.path().join("snapshots").join(format!("{legacy_id}.json")),
dir.path()
.join("snapshots")
.join(format!("{legacy_id}.json")),
serde_json::to_string(&legacy).unwrap(),
)
.unwrap();