1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

fix bug sync when a device add an iten whitout sync

This commit is contained in:
nishiki 2015-05-11 19:17:12 +02:00
parent 7a222798c5
commit 2d7dacb02c
3 changed files with 41 additions and 33 deletions

View file

@ -23,7 +23,7 @@ module MPW
attr_accessor :sync_user
attr_accessor :sync_pwd
attr_accessor :sync_path
attr_accessor :last_update
attr_accessor :last_sync
attr_accessor :dir_config
# Constructor
@ -82,7 +82,7 @@ module MPW
'sync_user' => sync_user,
'sync_pwd' => sync_pwd,
'sync_path' => sync_path,
'last_update' => 0
'last_sync' => 0
}
}
@ -139,17 +139,17 @@ module MPW
# @rtrn: true if the config file is correct
def checkconfig
config = YAML::load_file(@file_config)
@key = config['config']['key']
@share_keys = config['config']['share_keys']
@lang = config['config']['lang']
@file_gpg = config['config']['file_gpg']
@sync_type = config['config']['sync_type']
@sync_host = config['config']['sync_host']
@sync_port = config['config']['sync_port']
@sync_user = config['config']['sync_user']
@sync_pwd = config['config']['sync_pwd']
@sync_path = config['config']['sync_path']
@last_update = config['config']['last_update'].to_i
@key = config['config']['key']
@share_keys = config['config']['share_keys']
@lang = config['config']['lang']
@file_gpg = config['config']['file_gpg']
@sync_type = config['config']['sync_type']
@sync_host = config['config']['sync_host']
@sync_port = config['config']['sync_port']
@sync_user = config['config']['sync_user']
@sync_pwd = config['config']['sync_pwd']
@sync_path = config['config']['sync_path']
@last_sync = config['config']['last_sync'].to_i
if @key.empty? or @file_gpg.empty?
@error_msg = I18n.t('error.config.check')
@ -203,7 +203,7 @@ module MPW
# Set the last update when there is a sync
# @rtrn: true is the file has been updated
def set_last_update
def set_last_sync
config = {'config' => {'key' => @key,
'share_keys' => @share_keys,
'lang' => @lang,
@ -214,7 +214,7 @@ module MPW
'sync_user' => @sync_user,
'sync_pwd' => @sync_pwd,
'sync_path' => @sync_path,
'last_update' => Time.now.to_i
'last_sync' => Time.now.to_i
}
}

View file

@ -20,6 +20,7 @@ module MPW
attr_accessor :port
attr_accessor :comment
attr_accessor :last_edit
attr_accessor :last_sync
attr_accessor :created
# Constructor
@ -67,6 +68,11 @@ module MPW
return true
end
# Update last_sync
def set_last_sync
@last_sync = Time.now.to_i
end
# Delete all data
# @rtrn: true
def delete
@ -81,6 +87,7 @@ module MPW
@comment = nil
@created = nil
@last_edit = nil
@last_sync = nil
return true
end

View file

@ -68,34 +68,32 @@ module MPW
# Sync remote data and local data
# raise an exception if there is a problem
def sync
if not @remote.to_s.empty?
@local.list.each do |item|
update = false
# Update item
@remote.list.each do |r|
# Update item
if item.id == r.id
if item.last_edit < r.last_edit
raise item.error_msg if not item.update(name: r.name,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
password: r.password,
port: r.port,
comment: r.comment
raise item.error_msg if not item.update(name: r.name,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
password: r.password,
port: r.port,
comment: r.comment
)
end
update = true
r.delete
break
end
end
# Delete an old item
if not update and item.last_edit < @config.last_update
# Remove an old item
if item.last_sync < @config.last_sync
item.delete
end
end
@ -116,15 +114,18 @@ module MPW
created: r.created,
last_edit: r.last_edit
)
puts item.last_edit
raise @local.error_msg if not @local.add(item)
end
end
@local.list.each do |item|
item.set_last_sync
end
raise @mpw.error_msg if not @local.encrypt
raise @sync.error_msg if not @sync.update(@config.file_gpg)
@config.set_last_update
@config.set_last_sync
return true
rescue Exception => e