From 6d3bd00d4cce351c15583a1de3667729619c0c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Mon, 14 Mar 2022 10:17:21 +0000 Subject: [PATCH] fix: osh-encrypt-rsync: delete +a source files properly --- bin/cron/osh-encrypt-rsync.pl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/cron/osh-encrypt-rsync.pl b/bin/cron/osh-encrypt-rsync.pl index 89cec2d..28fd275 100755 --- a/bin/cron/osh-encrypt-rsync.pl +++ b/bin/cron/osh-encrypt-rsync.pl @@ -374,7 +374,16 @@ sub encrypt_multi { # transient file _log " ... deleting transient file $current_source_file" if $verbose; - $dryRun or unlink $current_source_file; + if (!$dryRun) { + if (!unlink $current_source_file) { + + # maybe it is +a? try to -a it blindly and retry + system('chattr', '-a', $current_source_file); + if (!unlink $current_source_file) { + _warn "Couldn't delete transient file '$current_source_file' ($!)"; + } + } + } } if ($error) { $success = 0; @@ -385,7 +394,16 @@ sub encrypt_multi { } if ($success and $remove_source_on_success) { _log " ... removing source file $source_file" if $verbose; - $dryRun or unlink $source_file; + if (!$dryRun) { + if (!unlink $source_file) { + + # maybe it is +a? try to -a it blindly and retry + system('chattr', '-a', $source_file); + if (!unlink $source_file) { + _warn "Couldn't delete source file '$source_file' ($!)"; + } + } + } } return !$success; }