mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 01:22:36 +08:00
5357ab3324
* SECURITY: Safely decompress backups when restoring. * Fix tests and update theme_controller_spec to work with zip files instead of .tar.gz
28 lines
709 B
Ruby
28 lines
709 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Compression
|
|
class Engine
|
|
UnsupportedFileExtension = Class.new(StandardError)
|
|
|
|
def self.default_strategies
|
|
[
|
|
Compression::Zip.new,
|
|
Compression::Pipeline.new([Compression::Tar.new, Compression::Gzip.new]),
|
|
Compression::Gzip.new,
|
|
Compression::Tar.new
|
|
]
|
|
end
|
|
|
|
def self.engine_for(filename, strategies: default_strategies)
|
|
strategy = strategies.detect(-> { raise UnsupportedFileExtension }) { |e| e.can_handle?(filename) }
|
|
new(strategy)
|
|
end
|
|
|
|
def initialize(strategy)
|
|
@strategy = strategy
|
|
end
|
|
|
|
delegate :extension, :decompress, :compress, :strip_directory, to: :@strategy
|
|
end
|
|
end
|