FIX: Raise or log error when deleting of backup fails

FIX: Raise or log error when deleting of backup fails

diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb
index 49c4252..bbdf0c5 100644
--- a/lib/backup_restore/backuper.rb
+++ b/lib/backup_restore/backuper.rb
@@ -256,9 +256,6 @@ module BackupRestore
       content_type = MiniMime.lookup_by_filename(@backup_filename).content_type
       archive_path = File.join(@archive_directory, @backup_filename)
       @store.upload_file(@backup_filename, archive_path, content_type)
-    ensure
-      log "Removing archive from local storage..."
-      FileUtils.remove_file(archive_path, force: true)
     end
 
     def after_create_hook
@@ -294,6 +291,7 @@ module BackupRestore
 
     def clean_up
       log "Cleaning stuff up..."
+      delete_uploaded_archive
       remove_tar_leftovers
       unpause_sidekiq
       disable_readonly_mode if Discourse.readonly_mode?
@@ -301,6 +299,19 @@ module BackupRestore
       refresh_disk_space
     end
 
+    def delete_uploaded_archive
+      return unless @store.remote?
+
+      archive_path = File.join(@archive_directory, @backup_filename)
+
+      if File.exist?(archive_path)
+        log "Removing archive from local storage..."
+        File.delete(archive_path)
+      end
+    rescue => ex
+      log "Something went wrong while deleting uploaded archive from local storage.", ex
+    end
+
     def refresh_disk_space
       log "Refreshing disk stats..."
       @store.reset_cache
diff --git a/lib/backup_restore/local_backup_store.rb b/lib/backup_restore/local_backup_store.rb
index ae1c06e..b80b3fb 100644
--- a/lib/backup_restore/local_backup_store.rb
+++ b/lib/backup_restore/local_backup_store.rb
@@ -33,7 +33,7 @@ module BackupRestore
       path = path_from_filename(filename)
 
       if File.exists?(path)
-        FileUtils.remove_file(path, force: true)
+        File.delete(path)
         reset_cache
       end
     end

GitHub sha: c94a2bc6

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: