From fa39689e3a120ce2e88bcdf73701453d4c26bd2d Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Tue, 11 Apr 2023 13:26:18 +0200 Subject: [PATCH] Bugfix crash unauthorized delete --- Capy64/Runtime/Libraries/FileSystem.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Capy64/Runtime/Libraries/FileSystem.cs b/Capy64/Runtime/Libraries/FileSystem.cs index 8daf2cf..1dcda59 100644 --- a/Capy64/Runtime/Libraries/FileSystem.cs +++ b/Capy64/Runtime/Libraries/FileSystem.cs @@ -426,19 +426,26 @@ public class FileSystem : IComponent L.Error("path not found"); } - var attr = File.GetAttributes(path); - if (attr.HasFlag(FileAttributes.Directory)) + try { - if (!recursive && Directory.GetFileSystemEntries(path).Any()) + var attr = File.GetAttributes(path); + if (attr.HasFlag(FileAttributes.Directory)) { - L.Error("directory not empty"); - return 0; + if (!recursive && Directory.GetFileSystemEntries(path).Any()) + { + L.Error("directory not empty"); + return 0; + } + Directory.Delete(path, recursive); + } + else + { + File.Delete(path); } - Directory.Delete(path, recursive); } - else + catch (Exception e) { - File.Delete(path); + return L.Error(e.Message); } return 0;