Skip to content

Commit 12de875

Browse files
committed
Delete empty directories
1 parent 0de37a4 commit 12de875

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/serious_python/bin/package_command.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ const junkFilesDesktop = [
6868
"**.cpp",
6969
"**.hpp",
7070
"**.typed",
71-
"**.a",
72-
"**.pdb",
7371
"**.pyi",
7472
"**.pxd",
7573
"**.pyx",
76-
"**/LICENSE",
74+
"**.a",
75+
"**.pdb",
7776
"**.dist-info",
7877
"**/__pycache__",
7978
];
@@ -461,21 +460,30 @@ class PackageCommand extends Command {
461460
}
462461

463462
Future<void> cleanupDir(Directory directory, List<String> filesGlobs) async {
464-
return cleanupDirRecursive(
463+
await cleanupDirRecursive(
465464
directory, filesGlobs.map((g) => Glob(g.replaceAll("\\", "/"))));
466465
}
467466

468-
Future<void> cleanupDirRecursive(
467+
Future<bool> cleanupDirRecursive(
469468
Directory directory, Iterable<Glob> globs) async {
469+
var emptyDir = true;
470470
for (var entity in directory.listSync()) {
471471
if (globs.any((g) => g.matches(entity.path.replaceAll("\\", "/"))) &&
472472
await entity.exists()) {
473473
verbose("Deleting ${entity.path}");
474474
await entity.delete(recursive: true);
475475
} else if (entity is Directory) {
476-
await cleanupDirRecursive(entity, globs);
476+
if (await cleanupDirRecursive(entity, globs)) {
477+
verbose("Deleting empty directory ${entity.path}");
478+
await entity.delete(recursive: true);
479+
} else {
480+
emptyDir = false;
481+
}
482+
} else {
483+
emptyDir = false;
477484
}
478485
}
486+
return emptyDir;
479487
}
480488

481489
Future<int> runExec(String execPath, List<String> args,

0 commit comments

Comments
 (0)