Method: Docker::Util.file_hash_from_paths

Defined in:
lib/docker/util.rb

.file_hash_from_paths(local_paths) ⇒ Object

Convenience method to get the file hash corresponding to an array of local paths.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/docker/util.rb', line 205

def file_hash_from_paths(local_paths)
  local_paths.each_with_object({}) do |local_path, file_hash|
    unless File.exist?(local_path)
      raise ArgumentError, "#{local_path} does not exist."
    end

    basename = File.basename(local_path)
    if File.directory?(local_path)
      tar = create_dir_tar(local_path)
      file_hash[basename] = {
        content: tar.read,
        permissions: filesystem_permissions(local_path)
      }
      tar.close
      FileUtils.rm(tar.path)
    else
      file_hash[basename] = {
        content: File.read(local_path, mode: 'rb'),
        permissions: filesystem_permissions(local_path)
      }
    end
  end
end