summaryrefslogtreecommitdiff
path: root/lib/leap_cli/ssh/backend.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/ssh/backend.rb')
-rw-r--r--lib/leap_cli/ssh/backend.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/leap_cli/ssh/backend.rb b/lib/leap_cli/ssh/backend.rb
index 67c6ec9a..80203b61 100644
--- a/lib/leap_cli/ssh/backend.rb
+++ b/lib/leap_cli/ssh/backend.rb
@@ -4,6 +4,7 @@
# common exceptions.
#
+require 'stringio'
require 'timeout'
require 'sshkit'
require 'leap_cli/ssh/formatter'
@@ -97,6 +98,28 @@ module LeapCli
@scripts ||= LeapCli::SSH::Scripts.new(self, @host.hostname)
end
+ #
+ # sshkit just passes upload! and download! to Net::SCP, but Net::SCP
+ # make it impossible to set the file permissions. Here is how the mode
+ # is determined, from upload.rb:
+ #
+ # mode = channel[:stat] ? channel[:stat].mode & 07777 : channel[:options][:mode]
+ #
+ # The stat info from the file always overrides the mode you pass in options.
+ # However, the channel[:options][:mode] will be applied for pure in-memory
+ # uploads. So, if the mode is set, we convert the upload to be a memory
+ # upload instead of a file upload.
+ #
+ # Stupid, but blame Net::SCP.
+ #
+ def upload!(src, dest, options={})
+ if options[:mode]
+ super(StringIO.new(File.read(src)), dest, options)
+ else
+ super(src, dest, options)
+ end
+ end
+
private
#