@@ -298,26 +298,30 @@ def durable_place(pname, file)
298298 raise ( RuntimeError , 'The "pname" of the durable is nil' ) if pname . nil?
299299 raise ( RuntimeError , 'The "pname" of the durable may not be empty' ) if pname . empty?
300300 raise ( RuntimeError , 'The "file" of the durable is nil' ) if file . nil?
301- raise ( RuntimeError , "The file '#{ file } ' is absent" ) unless File . exist? ( file )
302- if File . size ( file ) > 1024
303- raise (
304- RuntimeError ,
305- "The file '#{ file } ' is too big (#{ File . size ( file ) } bytes) for durable_place(), use durable_save() instead"
306- )
307- end
308301 id = nil
309- elapsed ( @loog , level : Logger ::INFO ) do
310- id = post (
311- home . append ( 'durable-place' ) ,
312- {
313- 'pname' => pname ,
314- 'file' => File . basename ( file ) ,
315- 'zip' => File . open ( file , 'rb' )
316- }
317- ) . headers [ 'X-Zerocracy-DurableId' ] . to_i
318- throw ( :"Durable ##{ id } (#{ file } , #{ File . size ( file ) } bytes) placed for job \" #{ pname } \" at #{ @host } " )
302+ File . open ( file , 'rb' ) do |f |
303+ raise ( RuntimeError , "The file '#{ file } ' is absent" ) unless f . stat . file?
304+ if f . size > 1024
305+ raise (
306+ RuntimeError ,
307+ "The file '#{ file } ' is too big (#{ f . size } bytes) for durable_place(), use durable_save() instead"
308+ )
309+ end
310+ elapsed ( @loog , level : Logger ::INFO ) do
311+ id = post (
312+ home . append ( 'durable-place' ) ,
313+ {
314+ 'pname' => pname ,
315+ 'file' => File . basename ( file ) ,
316+ 'zip' => f
317+ }
318+ ) . headers [ 'X-Zerocracy-DurableId' ] . to_i
319+ throw ( :"Durable ##{ id } (#{ file } , #{ f . size } bytes) placed for job \" #{ pname } \" at #{ @host } " )
320+ end
319321 end
320322 id
323+ rescue Errno ::ENOENT
324+ raise ( RuntimeError , "The file '#{ file } ' is absent" )
321325 end
322326
323327 # Save a single durable from local file to server.
0 commit comments