diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs
index 30e08ba944..fea0b5ef0e 100644
--- a/TGServerService/Program.cs
+++ b/TGServerService/Program.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
@@ -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,22 @@ 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))
+ { //this is probably a symlink
+ Directory.Delete(di.FullName);
+ return true;
+ }
+ return false;
+ }
+
///
/// Recursively empty a directory
///
@@ -67,6 +80,8 @@ namespace TGServerService
{
if (excludeRoot != null && excludeRoot.Contains(subDir.Name.ToLower()))
continue;
+ if (CheckDeleteSymlinkDir(subDir))
+ continue;
NormalizeAndDelete(subDir, null);
subDir.Delete(true);
}