Module: 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
- #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
63 64 65 66 67 68 69 |
# File 'lib/scope_file_access_archive.rb', line 63 def binary?(system_file) content = file_content(system_file) return false if content.empty? output = Cheetah.run("file", "-", stdin: content, stdout: :capture) !output.include?("ASCII") 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") files.select(&:directory?).each do |system_file| raise Machinery::Errors::FileUtilsError if !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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/scope_file_access_archive.rb', line 48 def file_content(system_file) if !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 |
#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
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scope_file_access_archive.rb', line 35 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 |