mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +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
|
end
|
||||||
|
|
||||||
# Sync data with remote file
|
# 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 @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"
|
tmp_file = "#{@wallet_file}.sync"
|
||||||
last_sync = @config['last_sync'].to_i
|
|
||||||
|
|
||||||
case @config['sync']['type']
|
case @config['sync']['type']
|
||||||
when 'sftp', 'scp', 'ssh'
|
when 'sftp', 'scp', 'ssh'
|
||||||
require "#{APP_ROOT}/../lib/mpw/sync/ssh.rb"
|
require "#{APP_ROOT}/../lib/mpw/sync/ssh.rb"
|
||||||
|
@ -370,7 +371,7 @@ class MPW
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove an old item
|
# 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
|
item.delete
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -230,7 +230,7 @@ class Cli
|
||||||
def add_key(key, file=nil)
|
def add_key(key, file=nil)
|
||||||
@mpw.add_key(key, file)
|
@mpw.add_key(key, file)
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
puts "#{I18n.t('form.add_key.valid')}".green
|
puts "#{I18n.t('form.add_key.valid')}".green
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -242,7 +242,7 @@ class Cli
|
||||||
def delete_key(key)
|
def delete_key(key)
|
||||||
@mpw.delete_key(key)
|
@mpw.delete_key(key)
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
puts "#{I18n.t('form.delete_key.valid')}".green
|
puts "#{I18n.t('form.delete_key.valid')}".green
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -269,7 +269,7 @@ class Cli
|
||||||
@mpw.add(item)
|
@mpw.add(item)
|
||||||
@mpw.set_password(item.id, password)
|
@mpw.set_password(item.id, password)
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
puts "#{I18n.t('form.add_item.valid')}".green
|
puts "#{I18n.t('form.add_item.valid')}".green
|
||||||
end
|
end
|
||||||
|
@ -298,7 +298,7 @@ class Cli
|
||||||
item.update(options)
|
item.update(options)
|
||||||
@mpw.set_password(item.id, password) if not password.empty?
|
@mpw.set_password(item.id, password) if not password.empty?
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
puts "#{I18n.t('form.update_item.valid')}".green
|
puts "#{I18n.t('form.update_item.valid')}".green
|
||||||
else
|
else
|
||||||
|
@ -330,7 +330,7 @@ class Cli
|
||||||
|
|
||||||
item.delete
|
item.delete
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
puts "#{I18n.t('form.delete_item.valid', id: id)}".green
|
puts "#{I18n.t('form.delete_item.valid', id: id)}".green
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
Loading…
Reference in a new issue