@@ -91,10 +91,6 @@ class LDP {
9191 } )
9292 }
9393
94- createReadStream ( path , start , end ) {
95- return fs . createReadStream ( path , start && end && { start, end} )
96- }
97-
9894 async readResource ( url ) {
9995 let releaseLock
10096 try {
@@ -377,7 +373,6 @@ class LDP {
377373 // This forces one more translation turtle -> desired
378374 return { stream, contentType : 'text/turtle' , container : true }
379375 } else {
380- let stream
381376 let chunksize , contentRange , start , end
382377 if ( options . range ) {
383378 const total = fs . statSync ( path ) . size
@@ -389,18 +384,26 @@ class LDP {
389384 chunksize = ( end - start ) + 1
390385 contentRange = 'bytes ' + start + '-' + end + '/' + total
391386 }
392- stream = this . createReadStream ( path )
393- return new Promise ( ( resolve , reject ) => {
394- stream
395- . on ( 'error' , function ( err ) {
396- debug . handlers ( `GET -- error reading ${ path } : ${ err . message } ` )
397- return reject ( error ( err , "Can't read file " + err ) )
398- } )
399- . on ( 'open' , function ( ) {
400- debug . handlers ( `GET -- Reading ${ path } ` )
401- return resolve ( { stream, contentType, container : false , contentRange, chunksize } )
402- } )
403- } )
387+ let releaseLock
388+ try {
389+ releaseLock = await lock ( path , { retries : 10 } )
390+ return await new Promise ( ( resolve , reject ) => {
391+ const stream = fs . createReadStream ( path , start && end && { start, end} )
392+ stream
393+ . on ( 'error' , function ( err ) {
394+ debug . handlers ( `GET -- error reading ${ path } : ${ err . message } ` )
395+ return reject ( error ( err , "Can't read file " + err ) )
396+ } )
397+ . on ( 'open' , function ( ) {
398+ debug . handlers ( `GET -- Reading ${ path } ` )
399+ return resolve ( { stream, contentType, container : false , contentRange, chunksize } )
400+ } )
401+ } )
402+ } finally {
403+ if ( releaseLock ) {
404+ await releaseLock ( )
405+ }
406+ }
404407 }
405408 }
406409
0 commit comments