lib/zold/commands/push.rb in zold-0.21.1 vs lib/zold/commands/push.rb in zold-0.21.2
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-# Copyright (c) 2018 Yegor Bugayenko
+# Copyright (c) 2018-2019 Zerocracy, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -90,10 +90,13 @@
private
def push(id, opts)
raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
+ @wallets.acq(id) do |wallet|
+ raise "The wallet #{id} is absent at #{wallet.path}" unless wallet.exists?
+ end
start = Time.now
total = Concurrent::AtomicFixnum.new
nodes = Concurrent::AtomicFixnum.new
done = Concurrent::AtomicFixnum.new
masters = Concurrent::AtomicFixnum.new
@@ -125,13 +128,10 @@
return 0
end
start = Time.now
uri = "/wallet/#{id}"
response = Tempfile.open do |f|
- @wallets.acq(id) do |wallet|
- raise "The wallet #{id} is absent" unless wallet.exists?
- FileUtils.copy_file(wallet.path, f.path)
- end
+ @wallets.acq(id) { |w| FileUtils.copy_file(w.path, f.path) }
r.http(uri).put(f)
end
@wallets.acq(id) do |wallet|
if response.status == 304
@log.info("#{r}: same version of #{wallet.mnemo} there, in #{Age.new(start, limit: 0.5)}")