From bd5faf9917a7b888f1026b51c3f2b13145cc80ee Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 30 Oct 2017 15:25:15 -0400 Subject: [PATCH] Fixes recursive symlink deletion --- TGServerService/Program.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs index 30e08ba944..aa10e583c6 100644 --- a/TGServerService/Program.cs +++ b/TGServerService/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; @@ -9,7 +9,7 @@ namespace TGServerService /// /// Entry point to the program /// - static void Main() => new Service(); + static void Main() => Service.Launch(); /// /// Copy a file from to , but first ensure the destination directory exists @@ -42,11 +42,8 @@ namespace TGServerService if (excludeRoot != null) for (var I = 0; I < excludeRoot.Count; ++I) excludeRoot[I] = excludeRoot[I].ToLower(); - if (!di.Attributes.HasFlag(FileAttributes.Directory)) - { //this is probably a symlink - Directory.Delete(di.FullName); + if (CheckDeleteSymlinkDir(di)) return; - } NormalizeAndDelete(di, excludeRoot); if (!ContentsOnly) { @@ -56,6 +53,16 @@ namespace TGServerService } } + static bool CheckDeleteSymlinkDir(DirectoryInfo di) + { + if (!di.Attributes.HasFlag(FileAttributes.Directory)) + { //this is probably a symlink + Directory.Delete(di.FullName); + return true; + } + return false; + } + /// /// Recursively empty a directory /// @@ -67,6 +74,8 @@ namespace TGServerService { if (excludeRoot != null && excludeRoot.Contains(subDir.Name.ToLower())) continue; + if (CheckDeleteSymlinkDir(subDir)) + continue; NormalizeAndDelete(subDir, null); subDir.Delete(true); }