Skip to content

Commit 915f706

Browse files
committed
post: harden totalSize against fs races
1 parent 9d38a7a commit 915f706

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

post.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ async function main() {
3939
}
4040

4141
async function totalSize(p) {
42-
const stat = await fs.stat(p);
43-
if (stat.isFile()) return stat.size;
44-
if (stat.isDirectory()) {
45-
let total = 0;
46-
for (const entry of await fs.readdir(p)) {
47-
total += await totalSize(path.join(p, entry));
42+
try {
43+
const stat = await fs.stat(p);
44+
if (stat.isFile()) return stat.size;
45+
if (stat.isDirectory()) {
46+
let total = 0;
47+
for (const entry of await fs.readdir(p)) {
48+
total += await totalSize(path.join(p, entry));
49+
}
50+
return total;
4851
}
49-
return total;
52+
return 0;
53+
} catch {
54+
return 0;
5055
}
51-
return 0;
5256
}
5357

5458
async function rmDirContents(dir) {

0 commit comments

Comments
 (0)