lib/nexussw/lxd/transport/mixins/helpers/upload_folder.rb in lxd-common-0.7.0 vs lib/nexussw/lxd/transport/mixins/helpers/upload_folder.rb in lxd-common-0.8.0

- old
+ new

@@ -2,23 +2,23 @@ module LXD class Transport module Mixins module Helpers module UploadFolder - def upload_folder(local_path, path) - upload_using_tarball(local_path, path) || upload_files_individually(local_path, path) + def upload_folder(local_path, path, options = {}) + upload_using_tarball(local_path, path, options) || upload_files_individually(local_path, path, options) end - def upload_files_individually(local_path, path) + def upload_files_individually(local_path, path, options = {}) Dir.entries(local_path).map { |f| (f == '.' || f == '..') ? nil : File.join(local_path, f) }.compact.each do |f| dest = File.join(path, File.basename(local_path)) - upload_files_individually f, dest if File.directory? f - upload_file f, File.join(dest, File.basename(f)) if File.file? f + upload_files_individually f, dest, options if File.directory? f + upload_file f, File.join(dest, File.basename(f)), options if File.file? f end end - def upload_using_tarball(local_path, path) + def upload_using_tarball(local_path, path, options = {}) return false unless can_archive? # TODO: should I return false upon error? i.e. retry with individual file uploads if this fails? # lets see how this does in the wild before deciding flag, ext = compression begin @@ -30,15 +30,19 @@ if File.zero? tfile.path @can_archive = false return false end fname = '/tmp/' + File.basename(tfile.path) + ".tar#{ext}" - upload_file tfile.path, fname + upload_file tfile.path, fname, options # TODO: serious: make sure the tar extract does an overwrite of existing files # multiple converge support as well as CI cycle/dev updated files get updated instead of .1 suffixed (?) # I think I need a flag (it's been a while) - # TODO: explore the chmod & make the same as if uploaded via CLI - execute("bash -c 'mkdir -p #{path} && cd #{path} && tar -xf #{fname} && rm -rf #{fname} && chmod -R 600 #{File.basename(local_path)}'").error! + myuid = options[:uid] || uid || (0 if is_a?(Mixins::CLI)) + mygid = options[:gid] || gid || (0 if is_a?(Mixins::CLI)) + mymode = options[:file_mode] || file_mode + chown = " && chown -R #{myuid}:#{mygid} #{File.basename(local_path)}" if myuid + chmod = " && chmod -R #{mymode} #{File.basename(local_path)}" if mymode + execute("bash -c 'mkdir -p #{path} && cd #{path} && tar -xf #{fname} && rm -rf #{fname}#{chmod}#{chown}'").error! ensure tfile.unlink end end