fix: update CLIFileExistenceChecker to accept containerId in constructor

This commit is contained in:
Justin Lin committed 2025-04-26 11:09:10 +08:00
1 parent 5077f9c677
commit f7860c6197
2 files changed
+16 -21

No files matched your search

+15 -20
View File
@@ -7,26 +7,21 @@ function sanitizeId(id: string) {
return id.replace(/[^a-zA-Z0-9]/g, '')
}
// eslint-disable-next-line import/prefer-default-export
export function checkFile(id: string, file: IFileInput) {
return new Promise<boolean>((resolve) => {
const cmd = buildFileCheckCmd(file)
// WARNING: This is vulnerable to command injection
execFile(
'docker',
['exec', sanitizeId(id), ...cmd],
{ timeout: 1000 },
(error) => {
const exists = !error
resolve(exists)
}
)
})
}
export class CLIFileExistenceChecker implements IFileExistenceChecker {
// eslint-disable-next-line class-methods-use-this
async exists(file: IFileInput) {
return checkFile(file.path, file)
constructor(private readonly containerId: string) {}
exists(file: IFileInput) {
return new Promise<boolean>((resolve) => {
const cmd = buildFileCheckCmd(file)
// WARNING: This is vulnerable to command injection
execFile(
'docker',
['exec', sanitizeId(this.containerId), ...cmd],
{ timeout: 1000 },
(error) => {
const exists = !error
resolve(exists)
}
)
})
}
}