From 7d7b3bd0535a66ed46e2295644446d11f2b1b172 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Sun, 5 May 2024 17:01:12 +0200 Subject: [PATCH] filesystem-functions.pl: Add btrfs_remove_snapshot() function Easy to use function to delete a snapshot by it's ID Signed-off-by: Stefan Schantl --- config/cfgroot/filesystem-functions.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/cfgroot/filesystem-functions.pl b/config/cfgroot/filesystem-functions.pl index 19a0978ae..10c24df86 100644 --- a/config/cfgroot/filesystem-functions.pl +++ b/config/cfgroot/filesystem-functions.pl @@ -664,6 +664,28 @@ sub btrfs_create_snapshot ($) { return; } +# +## Easy to use function to delete a snapshot by it's ID. +## +## Requires the numeric ID of the snapshot. +## Optional a volume can be specified if it differs from the default one. +# +sub btrfs_remove_snapshot ($$) { + my ($id, $volume) = @_; + + # Assign default value if no volume has been given. + $volume //="/"; + + # Call the btrfs binary to delete the requested snapshot. + my $ret = &General::system("$btrfs_bin", "subvolume", "delete", "-c", "-i", "$id", "$volume"); + + # Return the error code if there was one. + return $ret if ($ret); + + # Return nothing on success. + return; +} + # ## Private function to filter the output of btrfs_subvolume_list command. ## -- 2.39.5