Skip to content

Commit 530c76a

Browse files
committed
Fixed folders not being created recursively
1 parent 7c0879c commit 530c76a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/handlers/patch.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = handler
44

55
const bodyParser = require('body-parser')
66
const fs = require('fs')
7+
const fx = require('mkdir-recursive')
78
const debug = require('../debug').handlers
89
const error = require('../http-error')
910
const $rdf = require('rdflib')
@@ -56,6 +57,13 @@ async function patchHandler (req, res, next) {
5657
const patchObject = await parsePatch(url, patch.uri, patch.text)
5758
await checkPermission(req, patchObject)
5859

60+
// Check to see if folder exists
61+
const pathSplit = path.split('/')
62+
const directory = pathSplit.slice(0, pathSplit.length - 1).join('/')
63+
if (!fs.existsSync(directory)) {
64+
fx.mkdirSync(directory, { recursive: true })
65+
}
66+
5967
// Patch the graph and write it back to the file
6068
releaseLock = await lock(path, { retries: 10, realpath: false })
6169
const graph = await readGraph(resource)

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"li": "^1.0.1",
8686
"mashlib": "^0.7.18",
8787
"mime-types": "^2.1.11",
88+
"mkdir-recursive": "^0.4.0",
8889
"negotiator": "^0.6.0",
8990
"node-fetch": "^2.1.2",
9091
"node-forge": "^0.7.4",

0 commit comments

Comments
 (0)