mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: fix file condition checks
This commit is contained in:
1 parent
64215d3ef1
commit
4ab3096fa5
5 files changed
+16
-20
No files matched your search
@@ -8,6 +8,6 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w"
|
||||
"dev": "tsc -w"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
const fileTypes = {
|
||||
file: '-f',
|
||||
folder: '-d',
|
||||
link: '-L',
|
||||
socket: '-S',
|
||||
unknown: '-e',
|
||||
}
|
||||
import type { IFileCondition } from '@linux-odyssey/models'
|
||||
|
||||
export type FileType = keyof typeof fileTypes
|
||||
|
||||
export type File = {
|
||||
path: string
|
||||
type: FileType
|
||||
}
|
||||
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[] {
|
||||
export function buildFileCheckCmd(file: IFileCondition): string[] {
|
||||
const { path, type } = file
|
||||
return ['test', fileTypes[type] || '-e', sanitizePath(path)]
|
||||
return ['test', fileTypes.get(type) || '-e', sanitizePath(path)]
|
||||
}
|
||||
Reference in new issue
Block a user