mirror of
https://github.com/github/codeql-action.git
synced 2026-01-03 13:10:06 +08:00
Merge remote-tracking branch 'upstream/main' into aeisenberg/fix-config-files
This commit is contained in:
31
src/util.ts
31
src/util.ts
@@ -780,3 +780,34 @@ export async function useCodeScanningConfigInCli(
|
||||
(await codeQlVersionAbove(codeql, CODEQL_VERSION_CONFIG_FILES))
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns whether the path in the argument represents an existing directory.
|
||||
*/
|
||||
export function doesDirectoryExist(dirPath: string): boolean {
|
||||
try {
|
||||
const stats = fs.lstatSync(dirPath);
|
||||
return stats.isDirectory();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a recursive list of files in a given directory.
|
||||
*/
|
||||
export function listFolder(dir: string): string[] {
|
||||
if (!doesDirectoryExist(dir)) {
|
||||
return [];
|
||||
}
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
let files: string[] = [];
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile()) {
|
||||
files.push(path.resolve(dir, entry.name));
|
||||
} else if (entry.isDirectory()) {
|
||||
files = files.concat(listFolder(path.resolve(dir, entry.name)));
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user