rbbt-util 5.17.28 → 5.17.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b62b4d3d3b46cfcf8e631a471daf1cc574843cc8
4
- data.tar.gz: 5b284a5ef7ade80f035ece5978a3cd31c5ea1d03
3
+ metadata.gz: b1776d45c03dd038001efb190c498041002029e2
4
+ data.tar.gz: 460b271b717c540d6ea68799fc0194e5ab026a16
5
5
  SHA512:
6
- metadata.gz: a85420b0c5ad7ac41d5f6cd46add0d49bd1841658849acba2e06c5f4f57a3f854a93916789afbaa4794137ee4855a63e88cdf4a430cb8e5df5fcda868d8f2e39
7
- data.tar.gz: f36d892b81611a5e2fffc95c50ca5fb0cb6121aca61552a74d60e9c20ede3daf1d1bb1422b8f00b8c84414773e41b534ef71747e5ddcd2391ea0a2f6d729d23f
6
+ metadata.gz: 0f2da706209429c3fb3901fae18c0e133bdd97d43700d23f12aa3c5d86d81233db986b08ae3187a387788eb06d847438697a259a7dbb2901a29b12cd11220245
7
+ data.tar.gz: 1cb89ce33d0f81232729dc2eb1ee8ea7561d6494eb5ba2a33ed161c8eca0e9b75865ee2cf9142e9309cd6d6076d3e51c3ec867469194c7d734c05b8b3217e88c
data/lib/rbbt/persist.rb CHANGED
@@ -194,6 +194,7 @@ module Persist
194
194
 
195
195
  saver_thread = Thread.new(Thread.current) do |parent|
196
196
  begin
197
+ file.threads = []
197
198
  Thread.current["name"] = "file saver: " + path
198
199
  save_file(path, type, file, lockfile)
199
200
  rescue Aborted
@@ -205,12 +206,15 @@ module Persist
205
206
  file.abort if file.respond_to? :abort
206
207
  parent.raise $!
207
208
  raise $!
209
+ rescue Exception
210
+ Log.exception $!
211
+ raise $!
208
212
  end
209
213
  end
210
214
  ConcurrentStream.setup(out, :threads => saver_thread, :filename => path)
211
215
  out.callback = callback
212
216
  out.abort_callback = abort_callback
213
- out.lockfile = stream.lockfile if stream.respond_to? :lockfile
217
+ out.lockfile = stream.lockfile if stream.respond_to? :lockfile and stream.lockfile
214
218
  out
215
219
  end
216
220
 
@@ -225,8 +229,12 @@ module Persist
225
229
 
226
230
  if stream
227
231
  if persist_options[:no_load] == :stream
228
- res = tee_stream(stream, path, type, stream.respond_to?(:callback)? stream.callback : nil, stream.respond_to?(:abort_callback)? stream.abort_callback : nil, lockfile)
229
- #res.lockfile = lockfile
232
+ callback = stream.respond_to?(:callback)? stream.callback : nil
233
+ abort_callback = stream.respond_to?(:abort_callback)? stream.abort_callback : nil
234
+
235
+ res = tee_stream(stream, path, type, callback, abort_callback, lockfile)
236
+
237
+ res.lockfile = lockfile
230
238
 
231
239
  raise KeepLocked.new res
232
240
  else
@@ -278,6 +286,7 @@ module Persist
278
286
  Misc.insist do
279
287
  if is_persisted?(path, persist_options)
280
288
  Log.low "Persist up-to-date (suddenly): #{ path } - #{Misc.fingerprint persist_options}"
289
+ lockfile.unlock if lockfile.locked?
281
290
  return path if persist_options[:no_load]
282
291
  return load_file(path, type)
283
292
  end
@@ -50,10 +50,17 @@ module ConcurrentStream
50
50
  def join_threads
51
51
  if @threads and @threads.any?
52
52
  @threads.each do |t|
53
- t.join unless t == Thread.current
53
+ next if t == Thread.current
54
+ begin
55
+ #t.join if t.status == 'run'
56
+ t.join unless FalseClass === t.status
57
+ rescue Exception
58
+ Log.warn "Exception joining thread in ConcurrenStream: #{filename}"
59
+ raise $!
60
+ end
54
61
  end
55
- @threads = []
56
62
  end
63
+ @threads = []
57
64
  end
58
65
 
59
66
  def join_pids
@@ -20,10 +20,10 @@ module Misc
20
20
  LOCK_MUTEX = Mutex.new
21
21
  def self.lock(file, unlock = true, options = {})
22
22
  unlock, options = true, unlock if Hash === unlock
23
- return yield if file.nil?
23
+ return yield if file.nil? and not Lockfile === options[:lock]
24
+
24
25
  FileUtils.mkdir_p File.dirname(File.expand_path(file)) unless File.exists? File.dirname(File.expand_path(file))
25
26
 
26
- res = nil
27
27
 
28
28
  case options[:lock]
29
29
  when Lockfile
@@ -42,6 +42,8 @@ module Misc
42
42
  lockfile.lock
43
43
  end
44
44
 
45
+ res = nil
46
+
45
47
  begin
46
48
  res = yield lockfile
47
49
  rescue KeepLocked
@@ -50,8 +52,13 @@ module Misc
50
52
  ensure
51
53
  if unlock
52
54
  begin
53
- lockfile.unlock #if lockfile.locked?
55
+ if lockfile.locked?
56
+ lockfile.unlock
57
+ else
58
+ end
54
59
  rescue Exception
60
+ Log.warn "Exception unlocking: #{lockfile.path}"
61
+ Log.exception $!
55
62
  end
56
63
  end
57
64
  end
@@ -230,49 +230,57 @@ module Misc
230
230
  Misc.lock tmp_path_lock, lock_options do
231
231
 
232
232
  if Open.exists? path and not force
233
+ Log.warn "Path exists in sensiblewrite, not forcing update: #{ path }"
233
234
  Misc.consume_stream content
234
- return
235
- end
236
-
237
- FileUtils.mkdir_p File.dirname(tmp_path) unless File.directory? File.dirname(tmp_path)
238
- FileUtils.rm_f tmp_path if File.exists? tmp_path
239
- begin
240
- case
241
- when block_given?
242
- File.open(tmp_path, 'wb', &block)
243
- when String === content
244
- File.open(tmp_path, 'wb') do |f| f.write content end
245
- when (IO === content or StringIO === content or File === content)
246
-
247
- Open.write(tmp_path) do |f|
248
- f.sync = true
249
- while block = content.read(2048)
250
- f.write block
235
+ else
236
+ FileUtils.mkdir_p File.dirname(tmp_path) unless File.directory? File.dirname(tmp_path)
237
+ FileUtils.rm_f tmp_path if File.exists? tmp_path
238
+ begin
239
+ case
240
+ when block_given?
241
+ File.open(tmp_path, 'wb', &block)
242
+ when String === content
243
+ File.open(tmp_path, 'wb') do |f| f.write content end
244
+ when (IO === content or StringIO === content or File === content)
245
+
246
+ Open.write(tmp_path) do |f|
247
+ f.sync = true
248
+ while block = content.read(2048)
249
+ f.write block
250
+ end
251
251
  end
252
+ else
253
+ File.open(tmp_path, 'wb') do |f| end
252
254
  end
253
- else
254
- File.open(tmp_path, 'wb') do |f| end
255
- end
256
255
 
257
- begin
258
- Open.mv tmp_path, path, lock_options
256
+ begin
257
+ Open.mv tmp_path, path, lock_options
258
+ rescue Exception
259
+ raise $! unless File.exists? path
260
+ end
261
+
262
+ content.join if content.respond_to? :join and not content.joined?
263
+
264
+ if Lockfile === lock_options[:lock] and lock_options[:lock].locked?
265
+ lock_options[:lock].unlock
266
+ end
267
+ FileUtils.touch path if File.exists? path
268
+ rescue Aborted
269
+ Log.medium "Aborted sensiblewrite -- #{ Log.reset << Log.color(:blue, path) }"
270
+ content.abort if content.respond_to? :abort
271
+ Open.rm path if File.exists? path
272
+ rescue Exception
273
+ Log.medium "Exception in sensiblewrite: #{$!.message} -- #{ Log.color :blue, path }"
274
+ Log.exception $!
275
+ content.abort if content.respond_to? :abort
276
+ Open.rm path if File.exists? path
277
+ raise $!
259
278
  rescue
260
- raise $! unless File.exists? path
279
+ Log.exception $!
280
+ raise $!
281
+ ensure
282
+ FileUtils.rm_f tmp_path if File.exists? tmp_path
261
283
  end
262
- content.join if content.respond_to? :join
263
- FileUtils.touch path if File.exists? path
264
- rescue Aborted
265
- Log.medium "Aborted sensiblewrite -- #{ Log.reset << Log.color(:blue, path) }"
266
- content.abort if content.respond_to? :abort
267
- Open.rm path if File.exists? path
268
- rescue Exception
269
- Log.medium "Exception in sensiblewrite: #{$!.message} -- #{ Log.color :blue, path }"
270
- Log.exception $!
271
- content.abort if content.respond_to? :abort
272
- Open.rm path if File.exists? path
273
- raise $!
274
- ensure
275
- FileUtils.rm_f tmp_path if File.exists? tmp_path
276
284
  end
277
285
  end
278
286
  end
@@ -446,6 +454,8 @@ module Misc
446
454
 
447
455
  def self.save_stream(file, stream)
448
456
  out, save = Misc.tee_stream stream
457
+ out.filename = file
458
+ save.filename = file
449
459
 
450
460
  Thread.new(Thread.current) do |parent|
451
461
  begin
@@ -466,13 +476,11 @@ module Misc
466
476
  Misc.open_pipe do |sin|
467
477
  continue = true
468
478
  while continue
469
- line1 = streams.first.gets unless streams.first.eof?
470
- line2 = streams.last.gets unless streams.first.eof?
471
- continue = false if line1.nil? and line2.nil?
472
- sin.puts line1.strip if line1
473
- sin.puts line2.strip if line2
474
- line1 = nil
475
- line2 = nil
479
+ lines = streams.collect{|stream| stream.eof? ? nil : stream.gets }.compact
480
+ lines.each do |line|
481
+ sin.puts line
482
+ end
483
+ continue = false if lines.empty?
476
484
  end
477
485
  streams.each do |stream|
478
486
  stream.join if stream.respond_to? :join
@@ -121,7 +121,7 @@ class Step
121
121
  return nil if @exec or info_file.nil?
122
122
  value = Annotated.purge value if defined? Annotated
123
123
  Open.lock(info_file, :lock => info_lock) do
124
- i = info(false)
124
+ i = info(false).dup
125
125
  i[key] = value
126
126
  @info_cache = i
127
127
  Misc.sensiblewrite(info_file, INFO_SERIALIAZER.dump(i), :force => true, :lock => false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.17.28
4
+ version: 5.17.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake