Skip to content

Commit f5d2816

Browse files
committed
Revert "Lock file during patching."
This reverts commit 90dcfe6.
1 parent 01853af commit f5d2816

File tree

2 files changed

+11
-55
lines changed

2 files changed

+11
-55
lines changed

lib/handlers/patch.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const $rdf = require('rdflib')
1010
const crypto = require('crypto')
1111
const overQuota = require('../utils').overQuota
1212
const getContentType = require('../utils').getContentType
13-
const { lock } = require('proper-lockfile')
1413

1514
// Patch parsers by request body content type
1615
const PATCH_PARSERS = {
@@ -24,7 +23,6 @@ const DEFAULT_FOR_NEW_CONTENT_TYPE = 'text/turtle'
2423
async 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
}

package-lock.json

Lines changed: 4 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)