Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,31 @@ class Applesign {
await tools.asyncRimraf(placeholderdir);
}

// XXX some directory leftovers
async removeXCTests() {
fchk(arguments, []);
let dirsToCheck: Set<string> = new Set<string>();
const dir = this.config.appdir;
walk.walkSync(dir, (basedir: string, filename: string, stat: any) => {
const target = path.join(basedir, filename);
// if (target.toLowerCase().indexOf('/xct') !== -1)
if (target.toLowerCase().indexOf("xctest") !== -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (target.toLowerCase().indexOf("xctest") !== -1) {
if (target.toLowerCase().indexOf(".xctest") !== -1) {

This check is probably safer

this.emit("message", "Deleting " + target);
fs.unlinkSync(target);
dirsToCheck.add(basedir);
}
});
let removedDirs: Set<string> = new Set<string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s unclear to me the need to define a set of paths, an array should be fine and simpler because you cant have two different paths with the same path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify the loop iteration, the filter to remove the element from the set is adding an extra complication that is not necessary.

do {
removedDirs = new Set<string>();
for (const d of dirsToCheck) {
if (fs.readdirSync(d).length === 0) {
this.emit('message', 'Deleting ' + d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use “ instead of ‘ (see ci complains)

fs.rmdirSync(d);
removedDirs.add(d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what i understand this code is deleting empty directories. But if an empty directory is contained within a directory that only had this one it wont be removed, so the removal must happen recursively.

}
}
dirsToCheck = new Set([...dirsToCheck].filter((d) => !removedDirs.has(d)));
} while (removedDirs.size > 0);
}

async removeSigningFiles() {
Expand Down
Loading