From 9db18a15410c03013cb4db9e8f57ba5a6685ff22 Mon Sep 17 00:00:00 2001 From: Ankur A Sharma Date: Fri, 2 Sep 2022 21:32:29 +0000 Subject: [PATCH 1/2] file.Delete() if file.Exists --- GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs b/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs index 90bfd89137..459b71ccf8 100644 --- a/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs +++ b/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs @@ -27,7 +27,10 @@ public virtual void DeleteDirectory(string path, bool recursive = true, bool ign foreach (FileInfo file in directory.GetFiles()) { file.Attributes = FileAttributes.Normal; - file.Delete(); + if(file.Exists) + { + file.Delete(); + } } foreach (DirectoryInfo subDirectory in directory.GetDirectories()) From 4a18fa386c325b819f7ff937bba4286993d3ded7 Mon Sep 17 00:00:00 2001 From: Ankur A Sharma Date: Fri, 9 Sep 2022 01:33:20 +0000 Subject: [PATCH 2/2] put file.Delete() in try catch so it doesn't exit midway --- GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs b/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs index 459b71ccf8..f7e200ff5a 100644 --- a/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs +++ b/GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs @@ -26,11 +26,14 @@ public virtual void DeleteDirectory(string path, bool recursive = true, bool ign { foreach (FileInfo file in directory.GetFiles()) { - file.Attributes = FileAttributes.Normal; - if(file.Exists) + try { + file.Attributes = FileAttributes.Normal; file.Delete(); } + catch(Exception ex) + { + } } foreach (DirectoryInfo subDirectory in directory.GetDirectories())