Skip to content

A platform for community discussion. Free, open, simple.

DEV: Restoring backups didn't work on macOS

Gerhard Schlagerc0cd69d2807b
diff --git a/lib/backup_restore/backup_file_handler.rb b/lib/backup_restore/backup_file_handler.rb
index e0244b4787b..86103663e20 100644
--- a/lib/backup_restore/backup_file_handler.rb
+++ b/lib/backup_restore/backup_file_handler.rb
@@ -64,12 +64,19 @@ module BackupRestore
def decompress_archive
return if !@is_archive
+ # the transformation is a workaround for a bug which existed between v2.6.0.beta1 and v2.6.0.beta2
+ path_transformation =
+ case tar_implementation
+ when :gnu
+ ['--transform', 's|var/www/discourse/public/uploads/|uploads/|']
+ when :bsd
+ ['-s', '|var/www/discourse/public/uploads/|uploads/|']
+ end
+
log "Unzipping archive, this may take a while..."
Discourse::Utils.execute_command(
'tar', '--extract', '--gzip', '--file', @archive_path, '--directory', @tmp_directory,
- '--transform', 's|var/www/discourse/public/uploads/|uploads/|',
- # the transformation is a workaround for a bug which existed between v2.6.0.beta1 and v2.6.0.beta2
- failure_message: "Failed to decompress archive."
+ *path_transformation, failure_message: "Failed to decompress archive."
)
end
@@ -95,5 +102,19 @@ module BackupRestore
def available_size
SiteSetting.decompressed_backup_max_file_size_mb
end
+
+ def tar_implementation
+ @tar_version ||= begin
+ tar_version = Discourse::Utils.execute_command('tar', '--version')
+
+ if tar_version.include?("GNU tar")
+ :gnu
+ elsif tar_version.include?("bsdtar")
+ :bsd
+ else
+ raise "Unknown tar implementation: #{tar_version}"
+ end
+ end
+ end
end
end