Skip to content

Commit c450461

Browse files
committed
- Fix for safe delete
1 parent d76cac7 commit c450461

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

samples/codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
rm -rf examples
3+
rm -rf dist
44
rm swagger-codegen-cli-v2.jar
55
rm swagger-codegen-cli-v3.jar
66

src/utils/isSubdirectory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { relative } from 'path';
2+
3+
export function isSubDirectory(parent: string, child: string) {
4+
return relative(child, parent).startsWith('..');
5+
}

src/utils/writeClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { resolve } from 'path';
33
import { Client } from '../client/interfaces/Client';
44
import { HttpClient } from '../index';
55
import { mkdir, rmdir } from './fileSystem';
6+
import { isSubDirectory } from './isSubdirectory';
67
import { Templates } from './registerHandlebarTemplates';
78
import { writeClientCore } from './writeClientCore';
89
import { writeClientIndex } from './writeClientIndex';
@@ -41,6 +42,10 @@ export async function writeClient(
4142
const outputPathSchemas = resolve(outputPath, 'schemas');
4243
const outputPathServices = resolve(outputPath, 'services');
4344

45+
if (!isSubDirectory(process.cwd(), output)) {
46+
throw new Error(`Output folder is not a subdirectory of the current working directory`);
47+
}
48+
4449
await rmdir(outputPath);
4550
await mkdir(outputPath);
4651

0 commit comments

Comments
 (0)