DEV: Restoring backups didn't work on macOS

This is a follow-up for f51ccea028 because specs were failing on macOS. macOS uses bsdtar by default and the --transform option isn't supported by bsdtar. But the -s option is and it works the same.
This commit is contained in:
Gerhard Schlager 2020-08-27 19:03:23 +02:00
parent 1cc5e8ea63
commit c0cd69d280
No known key found for this signature in database
GPG Key ID: 943644A1A201E402
1 changed files with 24 additions and 3 deletions

View File

@ -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