Skip to content

Commit

Permalink
Merge pull request #4013 from zowe/v3.x/feature/mkdirp
Browse files Browse the repository at this point in the history
Minor `bin/libs/fs.mkdirp` update
  • Loading branch information
MarkAckert authored Sep 26, 2024
2 parents e178af9 + bdf64bb commit 1c1176d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bin/libs/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ export function resolvePath(...parts:string[]): string {
}

export function mkdirp(path:string, mode?: number): number {
if (!path) {
return 1;
}
let paths: string[] = [];
let parts = path.split('/');
let currentPath = '';
parts.forEach((part:string)=> {
currentPath+='/'+part;
if (currentPath.startsWith('//')) {
currentPath = currentPath.substring(1);
if (part) {
currentPath += '/' + part;
paths.push(currentPath);
}
paths.push(currentPath);
});

let firstMissingDir: number;
Expand All @@ -85,9 +87,9 @@ export function mkdirp(path:string, mode?: number): number {
}
}

common.printDebug('paths='+JSON.stringify(paths));
common.printDebug('fs.mkdir paths='+JSON.stringify(paths));
if (firstMissingDir >= paths.length) { return 0; }
common.printDebug('firstMissingDir='+paths[firstMissingDir]);
common.printDebug('fs.mkdir firstMissingDir='+paths[firstMissingDir]);

for (let i = firstMissingDir; i < paths.length; i++) {
let rc = os.mkdir(paths[i], mode ? mode : 0o777);
Expand Down

0 comments on commit 1c1176d

Please sign in to comment.