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

fix multiple bug in sync

This commit is contained in:
nishiki 2015-03-22 22:43:18 +01:00
parent ddbc20f635
commit 465b60fd41
2 changed files with 21 additions and 17 deletions

View file

@ -36,8 +36,10 @@ module MPW
@id = generate_id
@created = Time.now.to_i
else
@id = options[:id]
@created = options[:created]
@id = options[:id]
@created = options[:created]
@last_edit = options[:last_edit]
options[:no_update_last_edit] = true
end
update(options)
@ -60,7 +62,7 @@ module MPW
@password = options[:password] if options.has_key?(:password)
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
return true
end

View file

@ -70,7 +70,6 @@ module MPW
def sync
if not @remote.to_s.empty?
@local.list.each do |item|
j = 0
update = false
# Update item
@ -89,12 +88,10 @@ module MPW
end
update = true
item.delete
r.delete
break
end
j += 1
end
# Delete an old item
@ -106,24 +103,29 @@ module MPW
# Add item
@remote.list.each do |r|
puts r.last_edit
if r.last_edit > @config.last_update
item = Item.new(id: r.id,
name: r.name,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
password: r.password,
port: r.port,
comment: r.comment,
created: r.created
item = Item.new(id: r.id,
name: r.name,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
password: r.password,
port: r.port,
comment: r.comment,
created: r.created
last_edit: r.last_edit
)
puts item.last_edit
raise @local.error_msg if not @local.add(item)
end
end
raise @mpw.error_msg if not @local.encrypt
raise @sync.error_msg if not @sync.update(@config.file_gpg)
@config.set_last_update
return true
rescue Exception => e