[pve-devel] [PATCH v3 storage 03/13] Add archive_remove

Fabian Ebner f.ebner at proxmox.com
Tue Jun 30 10:24:19 CEST 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes in v3:
    * die if unlink of archive fails
    * check whether log file exists before trying to unlink it
    * warn if unlink of log file fails

 PVE/Storage.pm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index ac0dccd..bab2ad6 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1418,6 +1418,23 @@ sub archive_info {
     return $info;
 }
 
+sub archive_remove {
+    my ($archive_path) = @_;
+
+    my $dirname = dirname($archive_path);
+    my $archive_info = eval { archive_info($archive_path) } // {};
+    my $logfn = $archive_info->{logfilename};
+
+    unlink $archive_path or die "removing archive $archive_path failed: $!\n";
+
+    if (defined($logfn)) {
+	my $logpath = "$dirname/$logfn";
+	if (-e $logpath) {
+	    unlink $logpath or warn "removing log file $logpath failed: $!\n";
+	}
+    }
+}
+
 sub extract_vzdump_config_tar {
     my ($archive, $conf_re) = @_;
 
-- 
2.20.1





More information about the pve-devel mailing list