@@ -4,14 +4,16 @@ module.exports = handler
44
55const bodyParser = require ( 'body-parser' )
66const fs = require ( 'fs' )
7- const fx = require ( 'mkdir-recursive' )
7+ const mkdirp = require ( 'fs-extra' ) . mkdirp
88const debug = require ( '../debug' ) . handlers
99const error = require ( '../http-error' )
1010const $rdf = require ( 'rdflib' )
1111const crypto = require ( 'crypto' )
1212const overQuota = require ( '../utils' ) . overQuota
1313const getContentType = require ( '../utils' ) . getContentType
1414const withLock = require ( '../lock' )
15+ const { promisify } = require ( 'util' )
16+ const pathUtility = require ( 'path' )
1517
1618// Patch parsers by request body content type
1719const PATCH_PARSERS = {
@@ -60,7 +62,19 @@ async function patchHandler (req, res, next) {
6062 const pathSplit = path . split ( '/' )
6163 const directory = pathSplit . slice ( 0 , pathSplit . length - 1 ) . join ( '/' )
6264 if ( ! fs . existsSync ( directory ) ) {
63- fx . mkdirSync ( directory , { recursive : true } )
65+ const firstDirectoryRecursivelyCreated = await promisify ( mkdirp ) ( directory )
66+ if ( ldp . live ) {
67+ // Get parent for the directory made
68+ const parentDirectoryPath =
69+ pathUtility . dirname ( firstDirectoryRecursivelyCreated ) + pathUtility . sep
70+ // Get the url for the parent
71+ const parentDirectoryUrl = ( await ldp . resourceMapper . mapFileToUrl ( {
72+ path : parentDirectoryPath ,
73+ hostname : req . hostname
74+ } ) ) . url
75+ // Update websockets
76+ ldp . live ( new URL ( parentDirectoryUrl ) . pathname )
77+ }
6478 }
6579
6680 // Patch the graph and write it back to the file
0 commit comments