Compilation now avoids symlink recreation (#49)

This commit is contained in:
Jordan Brown
2017-06-12 16:02:05 -03:00
committed by Leo
parent 527c5c91e1
commit e7fb899a5e
2 changed files with 21 additions and 21 deletions
+19 -6
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
namespace TGServerService
@@ -10,24 +11,36 @@ namespace TGServerService
//Everything in this file is just generic helpers
//http://stackoverflow.com/questions/1701457/directory-delete-doesnt-work-access-denied-error-but-under-windows-explorer-it
public static void DeleteDirectory(string path, bool ContentsOnly = false)
public static void DeleteDirectory(string path, bool ContentsOnly = false, IList<string> excludeRoot = null)
{
var di = new DirectoryInfo(path);
if (!di.Exists)
return;
NormalizeAndDelete(di);
if(!ContentsOnly)
if (excludeRoot != null)
for (var I = 0; I < excludeRoot.Count; ++I)
excludeRoot[I] = excludeRoot[I].ToLower();
NormalizeAndDelete(di, excludeRoot);
if (!ContentsOnly)
{
if (excludeRoot != null && excludeRoot.Count > 0)
throw new Exception("Cannot fully delete folder with exclusions specified!");
di.Delete(true);
}
}
static void NormalizeAndDelete(DirectoryInfo dir)
static void NormalizeAndDelete(DirectoryInfo dir, IList<string> excludeRoot)
{
foreach (var subDir in dir.GetDirectories())
{
NormalizeAndDelete(subDir);
if (excludeRoot != null && excludeRoot.Contains(subDir.Name.ToLower()))
continue;
NormalizeAndDelete(subDir, null);
subDir.Delete(true);
}
foreach (var file in dir.GetFiles())
{
if (excludeRoot != null && excludeRoot.Contains(file.Name.ToLower()))
continue;
file.Attributes = FileAttributes.Normal;
}
}