diff --git a/lib/Item.rb b/lib/Item.rb index c14d0bd..ca4555e 100644 --- a/lib/Item.rb +++ b/lib/Item.rb @@ -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 diff --git a/lib/Sync.rb b/lib/Sync.rb index e054330..beb7100 100644 --- a/lib/Sync.rb +++ b/lib/Sync.rb @@ -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