From a646b02e45950977aef87f13d55a806568de96aa Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 02:00:35 +0530 Subject: [PATCH] provide incremental directories to mkdir --- .../src/modules/FileSystem/operations/upload.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index 8ed4eae2..ea2dcbad 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -152,12 +152,16 @@ const upload = async function(items, dirPath, options = {}){ // On the other hand if the file name is not blank(could be undefined), we need to create the file. fileName != "" && files.push(entries[i]) if (options.createFileParent && fileItem.includes('/')) { - let filePath = path.join(dirPath, dirLevel) - // Prevent duplicate parent directory creation - if(!uniqueDirs[filePath]){ - uniqueDirs[filePath] = true; - dirs.push({path: filePath}); - } + let incrementalDir; + dirLevel.split('/').forEach((directory) => { + incrementalDir = incrementalDir ? incrementalDir + '/' + directory : directory; + let filePath = path.join(dirPath, incrementalDir) + // Prevent duplicate parent directory creation + if(!uniqueDirs[filePath]){ + uniqueDirs[filePath] = true; + dirs.push({path: filePath}); + } + }) } } // stats about the upload to come