1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-20 01:50: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 end
# Sync the data with the server # Sync the data with the server
# @rtnr: true if the synchro is finish
def sync() def sync()
if !defined?(@sync) if !defined?(@sync)
@sync = Sync.new() @sync = Sync.new()
if @config.sync_host.nil? || @config.sync_port.nil? if !@config.sync_host.nil? && !@config.sync_port.nil?
@sync.disable() if !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix)
elsif !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix) puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
puts "#{I18n.t('sync.not_connect')}:\n#{@sync.error_msg}" end
end end
end end
begin begin
if !@mpw.sync(@sync.get(@passwd), @config.last_update) if @sync.enable
puts "#{I18n.t('display.error')}: #{@mpw.error_msg}" if !@mpw.sync(@sync.get(@passwd), @config.last_update)
end puts "#{I18n.t('display.error')}: #{@mpw.error_msg}"
elsif !@sync.update(File.open(@config.file_gpg).read)
if !@sync.update(File.open(@config.file_gpg).read) puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
puts "#{I18n.t('display.error')}: #{@sync.error_msg}" elsif !@config.setLastUpdate()
end puts "#{I18n.t('display.error')}: #{@config.error_msg}"
else
if !@config.setLastUpdate() return true
puts "#{I18n.t('display.error')}: #{@config.error_msg}" end
end end
rescue Exception => e rescue Exception => e
puts "#{I18n.t('sync.error')}:\n#{e}" puts "#{I18n.t('display.error')}: #{I18n.t('sync.error')}\n#{e}"
end end
return false
end end
# Create a new config file # Create a new config file

View file

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