From: Stefan Schantl Date: Sun, 5 May 2024 15:01:12 +0000 (+0200) Subject: filesystem-functions.pl: Add btrfs_remove_snapshot() function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d7b3bd0535a66ed46e2295644446d11f2b1b172;p=people%2Fstevee%2Fipfire-2.x.git 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 --- 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. ##