lib/capsaicin/files/remote.rb in capsaicin-0.1.5 vs lib/capsaicin/files/remote.rb in capsaicin-0.1.6

- old
+ new

@@ -54,16 +54,30 @@ end rescue Interrupt logger.trace "interrupted (Ctrl-C)" if logger end - def upload(*args) + def upload(from, to, options={}, &block) case _via when :system, :local_run - cp(*args) + cp from, to else - @config.upload(*args) + if _via.to_s[0,4] == 'sudo' + if to[-1]==?/ || to[-1]==?\ || directory?(to) + tof = File.basename from + to2, to = "#{to}/#{tof}", "/tmp/#{tof}-#{Time.now.utc.to_i}" + else + tof = File.basename to + to2, to = to, "/tmp/#{tof}-#{Time.now.utc.to_i}" + end + end + @config.upload(from, to, options, &block) + if to2 + run "chmod 0644 #{to}" + cp to, to2 + run "rm -f #{to}" + end end end def download(*args) case _via @@ -72,16 +86,30 @@ else @config.download(*args) end end - def put(from, to) + def put(data, path, options={}) case _via when :system, :local_run FileUtils::Verbose.copy_stream StringIO.new(from), to else - @config.put(from, to) + if _via.to_s[0,4] == 'sudo' + if path[-1]==?/ || path[-1]==?\ || directory?(path) + pathf = File.basename from + path2, path = "#{path}/#{pathf}", "/tmp/#{pathf}-#{Time.now.utc.to_i}" + else + pathf = File.basename path + path2, path = path, "/tmp/#{pathf}-#{Time.now.utc.to_i}" + end + end + @config.put(data, path, options) + if path2 + run "chmod 0644 #{path}" + cp path, path2 + run "rm -f #{path}" + end end end def cd(dir, options={}) if block_given? @@ -109,10 +137,25 @@ def tar_cj(dest, src, options={}, &filter) filter and abort "tar_cj: remote mode does not support a filtering proc" _r 'tar -cjf', Array(src).unshift(dest) end + def tar_x(dest, options={}, &filter) + filter and abort "tar_x: remote mode does not support a filtering proc" + _r 'tar -xf', [dest] + end + + def tar_xz(dest, options={}, &filter) + filter and abort "tar_xz: remote mode does not support a filtering proc" + _r 'tar -xzf', [dest] + end + + def tar_xj(dest, src, options={}, &filter) + filter and abort "tar_xj: remote mode does not support a filtering proc" + _r 'tar -xjf', Array(src).unshift(dest) + end + def tar_t(src, options={}, &filter) filter and abort "tar_t: remote mode does not support a filtering proc" _t 'tar -tf', [src] end @@ -170,7 +213,5 @@ end end end end - -Capistrano.plugin :remote_files, Capsaicin::Files::Remote