Skip to content

Commit 5b8d2d0

Browse files
committed
Fine. Preserve ordering at the cost of readability
1 parent e68cd3a commit 5b8d2d0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/archiveDirectory.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,13 @@ async function zipDirectory(
141141
}
142142
throw err;
143143
}
144-
// For security, filter out all symlinks
145-
const realFiles: typeof files = [];
146-
await Promise.all(
144+
// For security, filter out all symlinks. This code is a bit obtuse to preserve ordering.
145+
const realFiles = (await Promise.all(
147146
files.map(async (f) => {
148147
const stats = await fs.promises.lstat(f.name);
149-
if (!stats.isSymbolicLink()) {
150-
realFiles.push(f);
151-
}
148+
return stats.isSymbolicLink() ? null : f;
152149
}),
153-
);
150+
)).filter((fileOrNull): fileOrNull is typeof files[number] => fileOrNull !== null);
154151

155152
for (const file of realFiles) {
156153
const name = path.relative(sourceDirectory, file.name);

0 commit comments

Comments
 (0)