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:
parent
7a222798c5
commit
2d7dacb02c
3 changed files with 41 additions and 33 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ module MPW
|
|||
@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
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
17
lib/Sync.rb
17
lib/Sync.rb
|
@ -68,12 +68,12 @@ 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
|
||||
@remote.list.each do |r|
|
||||
|
||||
# Update item
|
||||
@remote.list.each do |r|
|
||||
if item.id == r.id
|
||||
if item.last_edit < r.last_edit
|
||||
raise item.error_msg if not item.update(name: r.name,
|
||||
|
@ -87,15 +87,13 @@ module MPW
|
|||
)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue