secure-file-check 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +42 -8
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -42,17 +42,51 @@ function isIgnored(filePath) {
|
|
|
42
42
|
|
|
43
43
|
async function walkDir(dir) {
|
|
44
44
|
const results = [];
|
|
45
|
-
const
|
|
45
|
+
const stack = [dir];
|
|
46
|
+
const seen = new Set();
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
const
|
|
48
|
+
while (stack.length) {
|
|
49
|
+
const current = stack.pop();
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
let realCurrent;
|
|
52
|
+
try {
|
|
53
|
+
realCurrent = await fs.realpath(current);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
realCurrent = current;
|
|
56
|
+
}
|
|
51
57
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
if (seen.has(realCurrent)) continue;
|
|
59
|
+
seen.add(realCurrent);
|
|
60
|
+
|
|
61
|
+
let list;
|
|
62
|
+
try {
|
|
63
|
+
list = await fs.readdir(current, { withFileTypes: true });
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// permission denied or not a directory -> skip
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const f of list) {
|
|
70
|
+
const fullPath = path.join(current, f.name);
|
|
71
|
+
|
|
72
|
+
if (isIgnored(fullPath)) continue;
|
|
73
|
+
|
|
74
|
+
if (f.isDirectory()) {
|
|
75
|
+
stack.push(fullPath);
|
|
76
|
+
} else if (f.isSymbolicLink()) {
|
|
77
|
+
// resolve symlink target and only traverse directories to avoid cycles
|
|
78
|
+
try {
|
|
79
|
+
const targetReal = await fs.realpath(fullPath);
|
|
80
|
+
const stat = await fs.stat(targetReal);
|
|
81
|
+
if (stat.isDirectory()) stack.push(targetReal);
|
|
82
|
+
else results.push(fullPath);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
// broken symlink or permission issue -> skip
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
results.push(fullPath);
|
|
89
|
+
}
|
|
56
90
|
}
|
|
57
91
|
}
|
|
58
92
|
|
package/package.json
CHANGED