Skip to content

Commit

Permalink
fix: filter invalid inode
Browse files Browse the repository at this point in the history
  • Loading branch information
likun7981 committed Jun 13, 2022
1 parent cfde39f commit 1fb5602
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/core/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export function getInodes(dest: string) {
.split('\n')
.forEach(file => {
if (Boolean(file) && !file.endsWith('/') && !file.endsWith(':')) {
const [inode] = parseFilePath(file)
inodes.push(inode)
const result = parseFilePath(file)
if(result) {
inodes.push(result[0])
}
}
})
return inodes
Expand Down
4 changes: 4 additions & 0 deletions src/core/parseFilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import fs from 'fs-extra'

const endsWithes = ['*', '@'];
const allNumber = /^[0-9]+$/
/**
* @description 解析出inode及绝对路径
* @param file inode+filepath
Expand All @@ -21,6 +22,9 @@ function parseFilePath(file: string, dir: string = '') {
}
})
}
if (!allNumber.test(inode)) {
return false
}
return [inode, filepath]
}

Expand Down
13 changes: 8 additions & 5 deletions src/core/parseLsirf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ function parseLs(dir: string, ignoreError = false) {
prevIsBlank = true
} else {
prevIsBlank = false
const [inode, fullPath] = parseFilePath(file, currentDir)
results.push({
inode,
fullPath,
})
const result = parseFilePath(file, currentDir)
if(result) {
const [inode, fullPath] = result
results.push({
inode,
fullPath,
})
}
}
})
return results;
Expand Down

0 comments on commit 1fb5602

Please sign in to comment.