From 7aed7dc59744af48869590b79fdc47248246ac34 Mon Sep 17 00:00:00 2001 From: Eric Trenkel Date: Sun, 13 Aug 2023 11:59:32 +0200 Subject: [PATCH] Fixed empty folders when deleting (#206) * 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 --- lib/api/wsl.dart | 14 ++++++++------ test/wsl_test.dart | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/api/wsl.dart b/lib/api/wsl.dart index 973ab25..26252e1 100644 --- a/lib/api/wsl.dart +++ b/lib/api/wsl.dart @@ -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; } diff --git a/test/wsl_test.dart b/test/wsl_test.dart index 8bec9a2..bf0e0bb 100644 --- a/test/wsl_test.dart +++ b/test/wsl_test.dart @@ -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(