Skip to content

Commit

Permalink
Fixed empty folders when deleting (#206)
Browse files Browse the repository at this point in the history
* Changed "Quick actions" to "snippets"

* Changed Community Actions to Snippets

* Version bump

* Version bump

* Changed snippet to code snippet

* Upgraded dependencies

* Fixed windows recreating distro folders
  • Loading branch information
bostrot authored Aug 13, 2023
1 parent 2ddfe87 commit 7aed7dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/api/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,15 @@ class WSLApi {

// Check if folder is empty and delete
String path = getInstancePath(distribution).path;
Directory dir = Directory(path);
if (dir.existsSync()) {
if (dir.listSync().isEmpty) {
dir.deleteSync();
// Wait 10 seconds in async then delete for Windows to release file
Future.delayed(const Duration(seconds: 10), () {
Directory dir = Directory(path);
if (dir.existsSync()) {
if (dir.listSync().isEmpty) {
dir.deleteSync(recursive: true);
}
}
}

});
return results.stdout;
}

Expand Down
3 changes: 3 additions & 0 deletions test/wsl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void main() {
await WSLApi().remove('test');
expect(await isInstance('test'), false);

// Check if folder is deleted
expect(await Directory('C:/WSL2-Distros/test').exists(), false);

// Test without download
// Test creating it
await createDistro(
Expand Down

0 comments on commit 7aed7dc

Please sign in to comment.