Module: Machinery::ScopeFileAccessArchive
- Defined in:
- lib/scope_file_access_archive.rb
Instance Method Summary collapse
- #binary?(system_file) ⇒ Boolean
- #export_files_as_tarballs(destination) ⇒ Object
- #file_content(system_file) ⇒ Object
- #has_file?(name) ⇒ Boolean
- #retrieve_files_from_system_as_archive(system, files, excluded_files) ⇒ Object
- #retrieve_trees_from_system_as_archive(system, trees, excluded_files, &callback) ⇒ Object
- #tarball_path(system_file) ⇒ Object
Instance Method Details
#binary?(system_file) ⇒ Boolean
73 74 75 76 77 78 |
# File 'lib/scope_file_access_archive.rb', line 73 def binary?(system_file) content = file_content(system_file) return false if content.empty? Machinery.content_is_binary?(content.slice(0, 4096)) end |
#export_files_as_tarballs(destination) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/scope_file_access_archive.rb', line 21 def export_files_as_tarballs(destination) FileUtils.cp(File.join(scope_file_store.path, "files.tgz"), destination) target = File.join(destination, "trees") self.select(&:directory?).each do |system_file| raise Machinery::Errors::FileUtilsError unless system_file.directory? tarball_target = File.join(target, File.dirname(system_file.name)) FileUtils.mkdir_p(tarball_target) FileUtils.cp(tarball_path(system_file), tarball_target) end end |
#file_content(system_file) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/scope_file_access_archive.rb', line 58 def file_content(system_file) unless extracted raise Machinery::Errors::FileUtilsError, "The requested file '#{system_file.name}' is not" \ " available because files for scope '#{scope_name}' were not extracted." end tarball_path = File.join(scope_file_store.path, "files.tgz") begin Cheetah.run("tar", "xfO", tarball_path, system_file.name.gsub(/^\//, ""), stdout: :capture) rescue raise Machinery::Errors::FileUtilsError, "The requested file '#{system_file.name}' was not found." end end |
#has_file?(name) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/scope_file_access_archive.rb', line 35 def has_file?(name) return true if any? { |file| file.name == name } if any? { |file| file.name == File.join(File.dirname(name), "") } tgz_file = File.join(scope_file_store.path, "trees", "#{File.dirname(name)}.tgz") return Cheetah.run("tar", "ztf", tgz_file, stdout: :capture).split(/\n/). any? { |f| "/#{f}" == name } end false end |
#retrieve_files_from_system_as_archive(system, files, excluded_files) ⇒ Object
2 3 4 5 |
# File 'lib/scope_file_access_archive.rb', line 2 def retrieve_files_from_system_as_archive(system, files, excluded_files) archive_path = File.join(scope_file_store.path, "files.tgz") system.create_archive(files, archive_path, excluded_files) end |
#retrieve_trees_from_system_as_archive(system, trees, excluded_files, &callback) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/scope_file_access_archive.rb', line 7 def retrieve_trees_from_system_as_archive(system, trees, excluded_files, &callback) trees.each_with_index do |tree, index| tree_name = File.basename(tree) parent_dir = File.dirname(tree) sub_dir = File.join("trees", parent_dir) scope_file_store.create_sub_directory(sub_dir) archive_path = File.join(scope_file_store.path, sub_dir, "#{tree_name}.tgz") system.create_archive(tree, archive_path, excluded_files) callback.call(index + 1) if callback end end |
#tarball_path(system_file) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/scope_file_access_archive.rb', line 45 def tarball_path(system_file) if system_file.directory? File.join( system_file.scope.scope_file_store.path, "trees", File.dirname(system_file.name), File.basename(system_file.name) + ".tgz" ) else File.join(system_file.scope.scope_file_store.path, "files.tgz") end end |