lib/zine/uploader_sftp.rb in zine-0.16.0 vs lib/zine/uploader_sftp.rb in zine-0.17.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'net/ssh'
require 'net/sftp'
require 'rainbow'
require 'set'
@@ -10,10 +12,11 @@
Node = Struct.new(:name, :path_string)
def initialize(build_dir, options, credentials, delete_file_array,
upload_file_array)
return unless options['method'] == 'sftp'
+
@build_dir = build_dir
@host = options['host']
@path = options['path_or_repo']
@verbose = options['verbose']
@credentials = credentials
@@ -65,10 +68,11 @@
def deploy_directories(sftp)
node_array = make_sparse_node_array @upload_file_array
node_array.each do |level|
level.each do |node|
next if node.nil?
+
path_string = node.path_string
mkdir_p(sftp, path_string)
puts "mkdir_p #{path_string}" if @verbose
end
end
@@ -94,11 +98,11 @@
remove_duplicates level_array # make it sparse
end
def mkdir_p(sftp, path)
sftp.mkdir!(File.join(@path, path), permissions: 0o755) # drwxr-xr-x
- rescue Net::SFTP::StatusException => error
- raise if error.code != 4 && error.code != 11 # folder already exists
+ rescue Net::SFTP::StatusException => e
+ raise if e.code != 4 && e.code != 11 # folder already exists
end
# for each level, if a node has the same name & same path it's a duplicate
def remove_duplicates(level_array)
level_array.map(&:uniq)