1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-17 08:30:04 +00:00

fix bug last_update when sync no work

This commit is contained in:
nishiki 2014-01-26 12:13:32 +01:00
parent 1400cf7834
commit 174a028238
2 changed files with 27 additions and 27 deletions

View file

@ -29,32 +29,35 @@ class Cli
end
# Sync the data with the server
# @rtnr: true if the synchro is finish
def sync()
if !defined?(@sync)
@sync = Sync.new()
if @config.sync_host.nil? || @config.sync_port.nil?
@sync.disable()
elsif !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix)
puts "#{I18n.t('sync.not_connect')}:\n#{@sync.error_msg}"
if !@config.sync_host.nil? && !@config.sync_port.nil?
if !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix)
puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
end
end
end
begin
if !@mpw.sync(@sync.get(@passwd), @config.last_update)
puts "#{I18n.t('display.error')}: #{@mpw.error_msg}"
end
if !@sync.update(File.open(@config.file_gpg).read)
puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
end
if !@config.setLastUpdate()
puts "#{I18n.t('display.error')}: #{@config.error_msg}"
if @sync.enable
if !@mpw.sync(@sync.get(@passwd), @config.last_update)
puts "#{I18n.t('display.error')}: #{@mpw.error_msg}"
elsif !@sync.update(File.open(@config.file_gpg).read)
puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
elsif !@config.setLastUpdate()
puts "#{I18n.t('display.error')}: #{@config.error_msg}"
else
return true
end
end
rescue Exception => e
puts "#{I18n.t('sync.error')}:\n#{e}"
puts "#{I18n.t('display.error')}: #{I18n.t('sync.error')}\n#{e}"
end
return false
end
# Create a new config file

View file

@ -13,15 +13,12 @@ require "#{APP_ROOT}/lib/MPW.rb"
class Sync
attr_accessor :error_msg
attr_accessor :enable
# Constructor
def initialize()
@error_msg = nil
end
# Disable the sync
def disable()
@sync = false
@enable = false
end
# Connect to server
@ -37,21 +34,21 @@ class Sync
@suffix = suffix
begin
@socket= TCPSocket.new(host, port)
@sync = true
@socket = TCPSocket.new(host, port)
@enable = true
rescue Exception => e
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
@sync = false
@enable = false
end
return @sync
return @enable
end
# Get data on server
# @args: gpg_password -> the gpg password
# @rtrn: nil if nothing data or error
def get(gpg_password)
if !@sync
if !@enable
return nil
end
@ -91,7 +88,7 @@ class Sync
# @args: data -> the data to send on server
# @rtrn: false if there is a problem
def update(data)
if !@sync
if !@enable
return true
end
@ -121,7 +118,7 @@ class Sync
# Close the connection
def close()
if !@sync
if !@enable
return
end