Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Handle unavailable attachments in backup job

Oliver Güntherd4b62d81706c
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rb
index be738609709..448fb74d681 100644
--- a/app/workers/backup_job.rb
+++ b/app/workers/backup_job.rb
@@ -158,11 +158,8 @@ class BackupJob < ::ApplicationJob
Zip::File.open(file_name, Zip::File::CREATE) do |zipfile|
attachments.each do |attachment|
- # If an attachment is destroyed on disk, skip i
- diskfile = attachment.diskfile
- next unless diskfile
-
- path = diskfile.path
+ path = local_disk_path(attachment)
+ next unless path
zipfile.add "attachment/file/#{attachment.id}/#{attachment[:file]}", path
@@ -179,6 +176,20 @@ class BackupJob < ::ApplicationJob
file_name
end
+ def local_disk_path(attachment)
+ # If an attachment is destroyed on disk, skip it
+ diskfile = attachment.diskfile
+ return unless diskfile
+
+ diskfile.path
+ rescue StandardError => e
+ Rails.logger.error do
+ "Failed to access attachment #{attachment.id} #{attachment.file&.path} for backup: #{e.message}"
+ end
+
+ nil
+ end
+
def remove_paths!(paths)
paths.each do |path|
FileUtils.rm_rf path