Fixes recursive symlink deletion

This commit is contained in:
Jordan Brown
2017-10-30 15:25:15 -04:00
committed by GitHub
parent af767305f9
commit bd5faf9917
+15 -6
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
@@ -9,7 +9,7 @@ namespace TGServerService
/// <summary>
/// Entry point to the program
/// </summary>
static void Main() => new Service();
static void Main() => Service.Launch();
/// <summary>
/// Copy a file from <paramref name="source"/> to <paramref name="dest"/>, 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;
}
/// <summary>
/// Recursively empty a directory
/// </summary>
@@ -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);
}