provide incremental directories to mkdir

This commit is contained in:
4nshuman 2024-10-20 02:00:35 +05:30
parent 4fdea7db66
commit a646b02e45

View File

@ -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. // 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]) fileName != "" && files.push(entries[i])
if (options.createFileParent && fileItem.includes('/')) { if (options.createFileParent && fileItem.includes('/')) {
let filePath = path.join(dirPath, dirLevel) let incrementalDir;
// Prevent duplicate parent directory creation dirLevel.split('/').forEach((directory) => {
if(!uniqueDirs[filePath]){ incrementalDir = incrementalDir ? incrementalDir + '/' + directory : directory;
uniqueDirs[filePath] = true; let filePath = path.join(dirPath, incrementalDir)
dirs.push({path: filePath}); // Prevent duplicate parent directory creation
} if(!uniqueDirs[filePath]){
uniqueDirs[filePath] = true;
dirs.push({path: filePath});
}
})
} }
} }
// stats about the upload to come // stats about the upload to come