Class: Gitlab::ImportExport::Project::ExportedRelationsMerger
- Inherits:
-
Object
- Object
- Gitlab::ImportExport::Project::ExportedRelationsMerger
- Includes:
- CommandLineUtil
- Defined in:
- lib/gitlab/import_export/project/exported_relations_merger.rb
Constant Summary
Constants included from CommandLineUtil
CommandLineUtil::CLEAN_DIR_IGNORE_FILE_NAMES, CommandLineUtil::CommandLineUtilError, CommandLineUtil::DEFAULT_DIR_MODE, CommandLineUtil::FileOversizedError, CommandLineUtil::HardLinkError, CommandLineUtil::UNTAR_MASK
Instance Method Summary collapse
-
#initialize(export_job:, shared:) ⇒ ExportedRelationsMerger
constructor
A new instance of ExportedRelationsMerger.
- #save ⇒ Object
Methods included from CommandLineUtil
#gunzip, #gzip, #gzip_with_options, #mkdir_p, #tar_cf, #tar_czf, #untar_xf, #untar_zxf
Constructor Details
#initialize(export_job:, shared:) ⇒ ExportedRelationsMerger
Returns a new instance of ExportedRelationsMerger.
9 10 11 12 |
# File 'lib/gitlab/import_export/project/exported_relations_merger.rb', line 9 def initialize(export_job:, shared:) @export_job = export_job @shared = shared end |
Instance Method Details
#save ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab/import_export/project/exported_relations_merger.rb', line 14 def save Dir.mktmpdir do |dirpath| export_job.relation_exports.each do |relation_export| relation = relation_export.relation upload = relation_export.upload filename = upload.export_file.filename tar_gz_full_path = File.join(dirpath, filename) decompress_path = File.join(dirpath, relation) Gitlab::PathTraversal.check_path_traversal!(tar_gz_full_path) Gitlab::PathTraversal.check_path_traversal!(decompress_path) # Download tar.gz download_or_copy_upload( upload.export_file, tar_gz_full_path, size_limit: relation_export.upload.export_file.size ) # Decompress tar.gz mkdir_p(decompress_path) untar_zxf(dir: decompress_path, archive: tar_gz_full_path) File.delete(tar_gz_full_path) # Merge decompressed files into export_path RecursiveMergeFolders.merge(decompress_path, shared.export_path) FileUtils.rm_r(decompress_path) rescue StandardError => e shared.error(e) false end end shared.errors.empty? end |