mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
fix multiple bug in sync
This commit is contained in:
parent
ddbc20f635
commit
465b60fd41
2 changed files with 21 additions and 17 deletions
|
@ -36,8 +36,10 @@ module MPW
|
||||||
@id = generate_id
|
@id = generate_id
|
||||||
@created = Time.now.to_i
|
@created = Time.now.to_i
|
||||||
else
|
else
|
||||||
@id = options[:id]
|
@id = options[:id]
|
||||||
@created = options[:created]
|
@created = options[:created]
|
||||||
|
@last_edit = options[:last_edit]
|
||||||
|
options[:no_update_last_edit] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
update(options)
|
update(options)
|
||||||
|
@ -60,7 +62,7 @@ module MPW
|
||||||
@password = options[:password] if options.has_key?(:password)
|
@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?
|
@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)
|
@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
|
return true
|
||||||
end
|
end
|
||||||
|
|
30
lib/Sync.rb
30
lib/Sync.rb
|
@ -70,7 +70,6 @@ module MPW
|
||||||
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|
|
||||||
j = 0
|
|
||||||
update = false
|
update = false
|
||||||
|
|
||||||
# Update item
|
# Update item
|
||||||
|
@ -89,12 +88,10 @@ module MPW
|
||||||
end
|
end
|
||||||
|
|
||||||
update = true
|
update = true
|
||||||
item.delete
|
r.delete
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
j += 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete an old item
|
# Delete an old item
|
||||||
|
@ -106,24 +103,29 @@ module MPW
|
||||||
|
|
||||||
# Add item
|
# Add item
|
||||||
@remote.list.each do |r|
|
@remote.list.each do |r|
|
||||||
|
puts r.last_edit
|
||||||
if r.last_edit > @config.last_update
|
if r.last_edit > @config.last_update
|
||||||
item = Item.new(id: r.id,
|
item = Item.new(id: r.id,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
group: r.group,
|
group: r.group,
|
||||||
host: r.host,
|
host: r.host,
|
||||||
protocol: r.protocol,
|
protocol: r.protocol,
|
||||||
user: r.user,
|
user: r.user,
|
||||||
password: r.password,
|
password: r.password,
|
||||||
port: r.port,
|
port: r.port,
|
||||||
comment: r.comment,
|
comment: r.comment,
|
||||||
created: r.created
|
created: r.created
|
||||||
|
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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
return true
|
return true
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
Loading…
Add table
Reference in a new issue