lib/capsaicin/files/remote.rb in joekhoobyar-capsaicin-0.1.6 vs lib/capsaicin/files/remote.rb in joekhoobyar-capsaicin-0.1.7
- old
+ new
@@ -59,11 +59,19 @@
def upload(from, to, options={}, &block)
case _via
when :system, :local_run
cp from, to
else
- to2, to = to, "/tmp/#{File.basename to}-#{Time.now.utc.to_i}" if _via.to_s[0,4] == 'sudo'
+ 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}"
@@ -83,10 +91,17 @@
def put(data, path, options={})
case _via
when :system, :local_run
FileUtils::Verbose.copy_stream StringIO.new(from), to
else
- path2, path = path, "/tmp/#{File.basename path}-#{Time.now.utc.to_i}" if _via.to_s[0,4] == 'sudo'
+ if _via.to_s[0,4] == 'sudo'
+ if path[-1]==?/ || path[-1]==?\\ || directory?(path)
+ abort "Target path is a directory!"
+ 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}"