Make commit output the UUID of the commit's snapshot

This commit is contained in:
Josh Hansen 2023-10-01 23:43:40 -07:00
parent db8d6e2efa
commit 9390ac92d2
5 changed files with 14 additions and 3 deletions

1
Cargo.lock generated
View file

@ -435,6 +435,7 @@ dependencies = [
"sudo",
"tempdir",
"thiserror",
"uuid",
"walkdir",
"xattr",
"xdg",

View file

@ -29,6 +29,7 @@ serde_json = "1.0.96"
sha2 = "0.10.8"
sudo = "0.6.0"
thiserror = "1.0.44"
uuid = "0.8.2"
walkdir = "2.3.3"
xattr = { version = "1.0.0", default-features = false }
xdg = "2.5.2"

View file

@ -228,6 +228,7 @@ Initialized table ./pizza with key: user.toppings
+./pizza/olive
+ Commit the change with a helpful comment
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m 'Add olive pizza' ./pizza
0dc9de01-08d3-384d-ac5d-c8e7f7eede8d
+ Make sure the new commit shows up in the log
+ /home/josh/Projects/Ghee/target/debug/ghee log ./pizza
commit 20c655bb-33da-4a44-9f75-91eb98af8e1a
@ -249,6 +250,7 @@ m./pizza/olive
+./pizza/pepperoni
+ Commit the new changes
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m 'Add pepperoni; add details to olive' ./pizza
ae56b31b-c5e3-c94d-9dc9-4b714635c23e
+ Make sure status and log reflect this
+ /home/josh/Projects/Ghee/target/debug/ghee status ./pizza
+ /home/josh/Projects/Ghee/target/debug/ghee log ./pizza
@ -504,6 +506,7 @@ Initialized table /home/josh/Projects/Ghee/snapshot/btrfs/pizza with key: user.t
+./pizza/olive
+ Commit the change with a helpful comment
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m 'Add olive pizza' /home/josh/Projects/Ghee/snapshot/btrfs/pizza
736136e1-43c0-cd44-81b7-a705e5f58ea0
+ Make sure the new commit shows up in the log
+ /home/josh/Projects/Ghee/target/debug/ghee log /home/josh/Projects/Ghee/snapshot/btrfs/pizza
commit 05aee894-48f1-3944-b04d-516f026b58c4
@ -525,6 +528,7 @@ m./pizza/olive
+./pizza/pepperoni
+ Commit the new changes
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m 'Add pepperoni; add details to olive' /home/josh/Projects/Ghee/snapshot/btrfs/pizza
90f70b63-0100-e046-b7fc-062029f1e4a7
+ Make sure status and log reflect this
+ /home/josh/Projects/Ghee/target/debug/ghee status /home/josh/Projects/Ghee/snapshot/btrfs/pizza
+ /home/josh/Projects/Ghee/target/debug/ghee log /home/josh/Projects/Ghee/snapshot/btrfs/pizza

View file

@ -222,8 +222,10 @@ fn run_command(cmd: &Commands) {
let cur = current_dir().unwrap();
let dir = dir.as_ref().unwrap_or(&cur);
commit(dir, message, *verbose)
let uuid = commit(dir, message, *verbose)
.unwrap_or_else(|e| panic!("Error committing {}: {}", dir.display(), e));
println!("{}", uuid);
}
Commands::Log { dir } => {

View file

@ -8,6 +8,7 @@ use btrfsutil::subvolume::{SnapshotFlags, Subvolume};
use file_owner::{owner_group, set_owner_group};
use sudo::escalate_if_needed;
use thiserror::Error;
use uuid::Uuid;
use crate::{
paths::{table_snapshot_path, table_snapshots_path},
@ -25,8 +26,10 @@ pub enum CommitErr {
/**
* Commit a table, storing its contents as a BTRFS snapshot
*
* Returns the commit UUID
*/
pub fn commit(dir: &PathBuf, message: &Option<String>, verbose: bool) -> Result<()> {
pub fn commit(dir: &PathBuf, message: &Option<String>, verbose: bool) -> Result<Uuid> {
escalate_if_needed().map_err(|_e| CommitErr::CouldNotEscalatePrivileges)?;
let subvol = Subvolume::get(dir.as_path()).map_err(|e| {
@ -84,7 +87,7 @@ pub fn commit(dir: &PathBuf, message: &Option<String>, verbose: bool) -> Result<
println!("Committed snapshot {}", uuid);
}
Ok(())
Ok(uuid)
}
// #[cfg(test)]