mofa 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,36 +40,53 @@ class UploadCmd < MofaCmd
40
40
 
41
41
  def upload_cookbook_pkg
42
42
  puts "Will use ssh_user #{Mofa::Config.config['binrepo_ssh_user']} and ssh_key_file #{Mofa::Config.config['binrepo_ssh_keyfile']}"
43
- puts "Uploading cookbook pkg #{cookbook.pkg_name} to binrepo import folder #{Mofa::Config.config['binrepo_host']}:#{Mofa::Config.config['binrepo_import_dir']}..."
44
43
 
45
44
  fail unless binrepo_up?
46
45
  import_dir = Mofa::Config.config['binrepo_import_dir']
47
46
 
48
- # if the upload target is not a proper binrepo with a designated ".../import" folder -> create the "right" folder structure
49
- unless Mofa::Config.config['binrepo_import_dir'].match(/import$/)
47
+ begin
48
+ # if the upload target is not a proper binrepo with a designated ".../import" folder -> create the "right" folder structure
49
+ unless Mofa::Config.config['binrepo_import_dir'].match(/import$/)
50
+ Net::SSH.start(Mofa::Config.config['binrepo_host'],
51
+ Mofa::Config.config['binrepo_ssh_user'],
52
+ :keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
53
+ :port => Mofa::Config.config['binrepo_ssh_port'],
54
+ :verbose => :error,
55
+ :use_agent => false) do |ssh|
56
+ puts "Remotely creating target dir \"#{import_dir}/#{cookbook.name}/#{cookbook.version}\""
57
+ out = ssh_exec!(ssh, "[ -d #{import_dir}/#{cookbook.name}/#{cookbook.version} ] || mkdir -p #{import_dir}/#{cookbook.name}/#{cookbook.version}")
58
+ fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
59
+ import_dir = "#{import_dir}/#{cookbook.name}/#{cookbook.version}"
60
+ end
61
+ end
62
+
63
+ # only upload if the file does not exist on the target host:
64
+ already_uploaded = false
50
65
  Net::SSH.start(Mofa::Config.config['binrepo_host'],
51
66
  Mofa::Config.config['binrepo_ssh_user'],
52
67
  :keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
53
68
  :port => Mofa::Config.config['binrepo_ssh_port'],
54
69
  :verbose => :error,
55
70
  :use_agent => false) do |ssh|
56
- puts "Remotely creating target dir \"#{import_dir}/#{cookbook.name}/#{cookbook.version}\""
57
- out = ssh_exec!(ssh, "[ -d #{import_dir}/#{cookbook.name}/#{cookbook.version} ] || mkdir -p #{import_dir}/#{cookbook.name}/#{cookbook.version}")
71
+ out = ssh_exec!(ssh, "[ -f #{import_dir}/#{cookbook.name}/#{cookbook.version}/#{cookbook.pkg_name} ] || echo -n already_exists")
58
72
  fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
59
- import_dir = "#{import_dir}/#{cookbook.name}/#{cookbook.version}"
73
+ already_uploaded = true if out[1] == 'already_exists'
60
74
  end
61
- end
62
75
 
63
- begin
64
- Net::SFTP.start(Mofa::Config.config['binrepo_host'],
65
- Mofa::Config.config['binrepo_ssh_user'],
66
- :keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
67
- :port => Mofa::Config.config['binrepo_ssh_port'],
68
- :verbose => :error,
69
- :use_agent => false) do |sftp|
70
- sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{import_dir}/#{cookbook.pkg_name}")
76
+ unless already_uploaded
77
+ puts "Uploading cookbook pkg #{cookbook.pkg_name} to binrepo import folder #{Mofa::Config.config['binrepo_host']}:#{Mofa::Config.config['binrepo_import_dir']}..."
78
+ Net::SFTP.start(Mofa::Config.config['binrepo_host'],
79
+ Mofa::Config.config['binrepo_ssh_user'],
80
+ :keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
81
+ :port => Mofa::Config.config['binrepo_ssh_port'],
82
+ :verbose => :error,
83
+ :use_agent => false) do |sftp|
84
+ sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{import_dir}/#{cookbook.pkg_name}")
85
+ end
86
+ puts "OK."
87
+ else
88
+ puts "Cookbook pkg #{cookbook.pkg_name} already exists in the binrepo. Will NOT upload it again."
71
89
  end
72
- puts "OK."
73
90
  rescue RuntimeError => e
74
91
  puts "Error: #{e.message}"
75
92
  raise "Failed to upload cookbook #{cookbook.name}!"
data/lib/mofa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mofa
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: