mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Compilation now avoids symlink recreation (#49)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user