Thibault Jouan 25935f8302 Improve mkdir so that permissions will be forced:
SFTP will honor umask on server side, and new directories won't get
expected permissions. We need to explicitly set permissions metadata for
new entries.
2014-09-25 21:35:06 +00:00

47 lines
977 B
Ruby

module Producer
module Core
class Remote
class FS
attr_reader :sftp
def initialize(sftp)
@sftp = sftp
end
def dir?(path)
sftp.stat!(path).directory?
rescue Net::SFTP::StatusException
false
end
def file?(path)
sftp.stat!(path).file?
rescue Net::SFTP::StatusException
false
end
def chmod(path, mode)
sftp.setstat! path, permissions: mode
end
def mkdir(path, mode = nil)
options = mode ? { permissions: mode } : {}
sftp.mkdir! path, options
end
def file_read(path)
sftp.file.open(path) { |f| content = f.read }
rescue Net::SFTP::StatusException
nil
end
def file_write(path, content, mode = nil)
sftp.file.open path, 'w', mode do |f|
f.write content
end
end
end
end
end
end