mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
21 lines
418 B
TypeScript
21 lines
418 B
TypeScript
export interface File {
|
|
path: string
|
|
type: string
|
|
}
|
|
|
|
const fileTypes = new Map([
|
|
['file', '-f'],
|
|
['folder', '-d'],
|
|
['link', '-L'],
|
|
['socket', '-S'],
|
|
])
|
|
|
|
function sanitizePath(path: string): string {
|
|
return path.replace(/[^a-zA-Z0-9._/-]/g, '')
|
|
}
|
|
|
|
export function buildFileCheckCmd(file: File): string[] {
|
|
const { path, type } = file
|
|
return ['test', fileTypes.get(type) || '-e', sanitizePath(path)]
|
|
}
|