From 66f07e907cda5140abd4bf318c52aa2e80e3b2f4 Mon Sep 17 00:00:00 2001 From: nishiki Date: Thu, 23 Jan 2014 23:04:13 +0100 Subject: [PATCH] fix when sync with the server --- lib/Cli.rb | 20 +++++++++++++++++--- mpw | 3 --- mpw-ssh | 5 ++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/Cli.rb b/lib/Cli.rb index 31c4a57..d68ac04 100644 --- a/lib/Cli.rb +++ b/lib/Cli.rb @@ -34,6 +34,8 @@ class Cli elsif !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix) puts "#{I18n.t('cli.sync.not_connect')}:\n#{@sync.error_msg}" end + + sync() end # Destructor @@ -44,9 +46,17 @@ class Cli # Sync the data with the server def sync() begin - @mpw.sync(@sync.get(@passwd), @config.last_update) - @sync.update(File.open(@config.file_gpg).read) - @config.setLastUpdate() + if !@mpw.sync(@sync.get(@passwd), @config.last_update) + puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}" + end + + if !@sync.update(File.open(@config.file_gpg).read) + puts "#{I18n.t('cli.display.error')}: #{@sync.error_msg}" + end + + if !@config.setLastUpdate() + puts "#{I18n.t('cli.display.error')}: #{@config.error_msg}" + end rescue Exception => e puts "#{I18n.t('cli.sync.error')}:\n#{e}" end @@ -150,6 +160,7 @@ class Cli if @mpw.update(name, group, server, protocol, login, passwd, port, comment) if @mpw.encrypt() + sync() puts I18n.t('cli.form.add.valid') else puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}" @@ -178,6 +189,7 @@ class Cli if @mpw.update(name, group, server, protocol, login, passwd, port, comment, id) if @mpw.encrypt() + sync() puts I18n.t('cli.form.update.valid') else puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}" @@ -212,6 +224,7 @@ class Cli if force if @mpw.remove(id) if @mpw.encrypt() + sync() puts I18n.t('cli.form.delete.valid', :id => id) else puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}" @@ -256,6 +269,7 @@ class Cli if force if @mpw.import(file) && @mpw.encrypt() + sync() puts I18n.t('cli.form.import.valid') else puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}" diff --git a/mpw b/mpw index 80f3344..f6660f6 100755 --- a/mpw +++ b/mpw @@ -97,7 +97,6 @@ config = MPWConfig.new(options[:config]) check_error = config.checkconfig() cli = Cli.new(lang, config) -cli.sync() # Setup a new config if !check_error || !options[:setup].nil? @@ -132,13 +131,11 @@ else begin cli.interactive() rescue SystemExit, Interrupt - cli.sync() cli = nil return 1 end end -cli.sync() cli = nil exit 0 diff --git a/mpw-ssh b/mpw-ssh index a517e9e..aa0e80a 100755 --- a/mpw-ssh +++ b/mpw-ssh @@ -55,8 +55,6 @@ cli.port = options[:port] search = ARGV[0] -cli.sync() - # Setup a new config if !check_error cli.setup(lang) @@ -64,9 +62,10 @@ if !check_error elsif ARGV.length < 1 puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]" exit 2 +else + cli.ssh(search) end -cli.ssh(search) cli = nil exit 0