Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bin/libs/fs.mkdirp update #4013

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading