@@ -10,7 +10,6 @@ const $rdf = require('rdflib')
1010const crypto = require ( 'crypto' )
1111const overQuota = require ( '../utils' ) . overQuota
1212const getContentType = require ( '../utils' ) . getContentType
13- const { lock } = require ( 'proper-lockfile' )
1413
1514// Patch parsers by request body content type
1615const PATCH_PARSERS = {
@@ -24,7 +23,6 @@ const DEFAULT_FOR_NEW_CONTENT_TYPE = 'text/turtle'
2423async function patchHandler ( req , res , next ) {
2524 debug ( `PATCH -- ${ req . originalUrl } ` )
2625 res . header ( 'MS-Author-Via' , 'SPARQL' )
27- let releaseLock
2826 try {
2927 // Obtain details of the target resource
3028 const ldp = req . app . locals . ldp
@@ -52,24 +50,22 @@ async function patchHandler (req, res, next) {
5250 throw error ( 415 , `Unsupported patch content type: ${ patch . contentType } ` )
5351 }
5452
55- // Parse the patch document and verify permissions
56- const patchObject = await parsePatch ( url , patch . uri , patch . text )
57- await checkPermission ( req , patchObject )
53+ // Parse the target graph and the patch document,
54+ // and verify permission for performing this specific patch
55+ const [ graph , patchObject ] = await Promise . all ( [
56+ readGraph ( resource ) ,
57+ parsePatch ( url , patch . uri , patch . text )
58+ . then ( patchObject => checkPermission ( req , patchObject ) )
59+ ] )
5860
5961 // Patch the graph and write it back to the file
60- releaseLock = await lock ( path , { retries : 10 , realpath : false } )
61- const graph = await readGraph ( resource )
6262 await applyPatch ( patchObject , graph , url )
6363 const result = await writeGraph ( graph , resource , ldp . resourceMapper . rootPath , ldp . serverUri )
6464
6565 // Send the result to the client
6666 res . send ( result )
6767 } catch ( err ) {
6868 return next ( err )
69- } finally {
70- if ( releaseLock ) {
71- await releaseLock ( )
72- }
7369 }
7470 return next ( )
7571}
0 commit comments