mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
fix when sync with the server
This commit is contained in:
parent
c654dac532
commit
66f07e907c
3 changed files with 19 additions and 9 deletions
20
lib/Cli.rb
20
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}"
|
||||
|
|
3
mpw
3
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
|
||||
|
|
5
mpw-ssh
5
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
|
||||
|
|
Loading…
Add table
Reference in a new issue