mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
no sync if last sync < 5min
This commit is contained in:
parent
8bfcb29bdf
commit
1036304727
2 changed files with 10 additions and 9 deletions
|
@ -316,12 +316,13 @@ class MPW
|
|||
end
|
||||
|
||||
# Sync data with remote file
|
||||
def sync
|
||||
# @args: force -> force the sync
|
||||
def sync(force=false)
|
||||
return if @config.empty? or @config['sync']['type'].to_s.empty?
|
||||
return if get_last_sync < Time.now.to_i + 300 and not force
|
||||
|
||||
tmp_file = "#{@wallet_file}.sync"
|
||||
last_sync = @config['last_sync'].to_i
|
||||
|
||||
|
||||
case @config['sync']['type']
|
||||
when 'sftp', 'scp', 'ssh'
|
||||
require "#{APP_ROOT}/../lib/mpw/sync/ssh.rb"
|
||||
|
@ -370,7 +371,7 @@ class MPW
|
|||
end
|
||||
|
||||
# Remove an old item
|
||||
if not update and item.last_sync.to_i < last_sync and item.last_edit < last_sync
|
||||
if not update and item.last_sync.to_i < get_last_sync and item.last_edit < get_last_sync
|
||||
item.delete
|
||||
end
|
||||
end
|
||||
|
|
|
@ -230,7 +230,7 @@ class Cli
|
|||
def add_key(key, file=nil)
|
||||
@mpw.add_key(key, file)
|
||||
@mpw.write_data
|
||||
@mpw.sync if @sync
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.add_key.valid')}".green
|
||||
rescue Exception => e
|
||||
|
@ -242,7 +242,7 @@ class Cli
|
|||
def delete_key(key)
|
||||
@mpw.delete_key(key)
|
||||
@mpw.write_data
|
||||
@mpw.sync if @sync
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.delete_key.valid')}".green
|
||||
rescue Exception => e
|
||||
|
@ -269,7 +269,7 @@ class Cli
|
|||
@mpw.add(item)
|
||||
@mpw.set_password(item.id, password)
|
||||
@mpw.write_data
|
||||
@mpw.sync if @sync
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.add_item.valid')}".green
|
||||
end
|
||||
|
@ -298,7 +298,7 @@ class Cli
|
|||
item.update(options)
|
||||
@mpw.set_password(item.id, password) if not password.empty?
|
||||
@mpw.write_data
|
||||
@mpw.sync if @sync
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.update_item.valid')}".green
|
||||
else
|
||||
|
@ -330,7 +330,7 @@ class Cli
|
|||
|
||||
item.delete
|
||||
@mpw.write_data
|
||||
@mpw.sync if @sync
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.delete_item.valid', id: id)}".green
|
||||
rescue Exception => e
|
||||
|
|
Loading…
Reference in a new issue