mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
29 lines
708 B
JavaScript
29 lines
708 B
JavaScript
import { execFile } from 'child_process'
|
|
|
|
import { buildFileCheckCmd } from '@linux-odyssey/utils'
|
|
|
|
function sanitizeId(id) {
|
|
return id.replace(/[^a-zA-Z0-9]/g, '')
|
|
}
|
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
export function checkFile(id, file) {
|
|
return new Promise((resolve, reject) => {
|
|
const cmd = buildFileCheckCmd(file)
|
|
// WARNING: This is vulnerable to command injection
|
|
execFile(
|
|
'docker',
|
|
['exec', sanitizeId(id), ...cmd],
|
|
{ timeout: 1000 },
|
|
(error) => {
|
|
const exists = !error
|
|
if (exists === file.exists) {
|
|
resolve(true)
|
|
} else {
|
|
reject(new Error('File check failed'))
|
|
}
|
|
}
|
|
)
|
|
})
|
|
}
|