From bd5faf9917a7b888f1026b51c3f2b13145cc80ee Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 30 Oct 2017 15:25:15 -0400 Subject: [PATCH 1/3] 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); } From 3c3128cb853c4d3f30e10c9acf4e01f6d8daa2ed Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 30 Oct 2017 15:25:52 -0400 Subject: [PATCH 2/3] Remove reference to future API --- TGServerService/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs index aa10e583c6..1fc9a14285 100644 --- a/TGServerService/Program.cs +++ b/TGServerService/Program.cs @@ -9,7 +9,7 @@ namespace TGServerService /// /// Entry point to the program /// - static void Main() => Service.Launch(); + static void Main() => new Service(); /// /// Copy a file from to , but first ensure the destination directory exists From 459708c0fa532a736a4bdc0dad0080e0b2312201 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 30 Oct 2017 15:27:34 -0400 Subject: [PATCH 3/3] Add documentation --- TGServerService/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs index 1fc9a14285..fea0b5ef0e 100644 --- a/TGServerService/Program.cs +++ b/TGServerService/Program.cs @@ -53,6 +53,12 @@ namespace TGServerService } } + + /// + /// Properly unlinks directory if it is a symlink + /// + /// for the directory in question + /// if was a symlink and deleted, otherwise static bool CheckDeleteSymlinkDir(DirectoryInfo di) { if (!di.Attributes.HasFlag(FileAttributes.Directory))