mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-20 21:34:35 +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_user
|
||||||
attr_accessor :sync_pwd
|
attr_accessor :sync_pwd
|
||||||
attr_accessor :sync_path
|
attr_accessor :sync_path
|
||||||
attr_accessor :last_update
|
attr_accessor :last_sync
|
||||||
attr_accessor :dir_config
|
attr_accessor :dir_config
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
|
@ -82,7 +82,7 @@ module MPW
|
||||||
'sync_user' => sync_user,
|
'sync_user' => sync_user,
|
||||||
'sync_pwd' => sync_pwd,
|
'sync_pwd' => sync_pwd,
|
||||||
'sync_path' => sync_path,
|
'sync_path' => sync_path,
|
||||||
'last_update' => 0
|
'last_sync' => 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ module MPW
|
||||||
@sync_user = config['config']['sync_user']
|
@sync_user = config['config']['sync_user']
|
||||||
@sync_pwd = config['config']['sync_pwd']
|
@sync_pwd = config['config']['sync_pwd']
|
||||||
@sync_path = config['config']['sync_path']
|
@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?
|
if @key.empty? or @file_gpg.empty?
|
||||||
@error_msg = I18n.t('error.config.check')
|
@error_msg = I18n.t('error.config.check')
|
||||||
|
@ -203,7 +203,7 @@ module MPW
|
||||||
|
|
||||||
# Set the last update when there is a sync
|
# Set the last update when there is a sync
|
||||||
# @rtrn: true is the file has been updated
|
# @rtrn: true is the file has been updated
|
||||||
def set_last_update
|
def set_last_sync
|
||||||
config = {'config' => {'key' => @key,
|
config = {'config' => {'key' => @key,
|
||||||
'share_keys' => @share_keys,
|
'share_keys' => @share_keys,
|
||||||
'lang' => @lang,
|
'lang' => @lang,
|
||||||
|
@ -214,7 +214,7 @@ module MPW
|
||||||
'sync_user' => @sync_user,
|
'sync_user' => @sync_user,
|
||||||
'sync_pwd' => @sync_pwd,
|
'sync_pwd' => @sync_pwd,
|
||||||
'sync_path' => @sync_path,
|
'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 :port
|
||||||
attr_accessor :comment
|
attr_accessor :comment
|
||||||
attr_accessor :last_edit
|
attr_accessor :last_edit
|
||||||
|
attr_accessor :last_sync
|
||||||
attr_accessor :created
|
attr_accessor :created
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
|
@ -67,6 +68,11 @@ module MPW
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Update last_sync
|
||||||
|
def set_last_sync
|
||||||
|
@last_sync = Time.now.to_i
|
||||||
|
end
|
||||||
|
|
||||||
# Delete all data
|
# Delete all data
|
||||||
# @rtrn: true
|
# @rtrn: true
|
||||||
def delete
|
def delete
|
||||||
|
@ -81,6 +87,7 @@ module MPW
|
||||||
@comment = nil
|
@comment = nil
|
||||||
@created = nil
|
@created = nil
|
||||||
@last_edit = nil
|
@last_edit = nil
|
||||||
|
@last_sync = nil
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
17
lib/Sync.rb
17
lib/Sync.rb
|
@ -68,12 +68,12 @@ module MPW
|
||||||
# Sync remote data and local data
|
# Sync remote data and local data
|
||||||
# raise an exception if there is a problem
|
# raise an exception if there is a problem
|
||||||
def sync
|
def sync
|
||||||
|
|
||||||
if not @remote.to_s.empty?
|
if not @remote.to_s.empty?
|
||||||
@local.list.each do |item|
|
@local.list.each do |item|
|
||||||
update = false
|
@remote.list.each do |r|
|
||||||
|
|
||||||
# Update item
|
# Update item
|
||||||
@remote.list.each do |r|
|
|
||||||
if item.id == r.id
|
if item.id == r.id
|
||||||
if item.last_edit < r.last_edit
|
if item.last_edit < r.last_edit
|
||||||
raise item.error_msg if not item.update(name: r.name,
|
raise item.error_msg if not item.update(name: r.name,
|
||||||
|
@ -87,15 +87,13 @@ module MPW
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
update = true
|
|
||||||
r.delete
|
r.delete
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete an old item
|
# Remove an old item
|
||||||
if not update and item.last_edit < @config.last_update
|
if item.last_sync < @config.last_sync
|
||||||
item.delete
|
item.delete
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -116,15 +114,18 @@ module MPW
|
||||||
created: r.created,
|
created: r.created,
|
||||||
last_edit: r.last_edit
|
last_edit: r.last_edit
|
||||||
)
|
)
|
||||||
puts item.last_edit
|
|
||||||
raise @local.error_msg if not @local.add(item)
|
raise @local.error_msg if not @local.add(item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@local.list.each do |item|
|
||||||
|
item.set_last_sync
|
||||||
|
end
|
||||||
|
|
||||||
raise @mpw.error_msg if not @local.encrypt
|
raise @mpw.error_msg if not @local.encrypt
|
||||||
raise @sync.error_msg if not @sync.update(@config.file_gpg)
|
raise @sync.error_msg if not @sync.update(@config.file_gpg)
|
||||||
|
|
||||||
@config.set_last_update
|
@config.set_last_sync
|
||||||
|
|
||||||
return true
|
return true
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
Loading…
Add table
Reference in a new issue