From e7fb899a5ed1e85f176f14c9eb04aa1d78f02d91 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 12 Jun 2017 15:02:05 -0400 Subject: [PATCH] Compilation now avoids symlink recreation (#49) --- TGServerService/Compiler.cs | 17 ++--------------- TGServerService/Program.cs | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 2658a3eac9..5f50b91390 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -38,6 +38,7 @@ namespace TGServerService const string LiveDirTest = GameDirLive + LiveFile; List copyExcludeList = new List { ".git", "data", "config", "libmysql.dll" }; //shit we handle + List deleteExcludeList = new List { "data", "config", "libmysql.dll" }; //shit we handle object CompilerLock = new object(); TGCompilerStatus compilerCurrentStatus; @@ -287,24 +288,10 @@ namespace TGServerService SendMessage("DM: Compiling..."); var resurrectee = GetStagingDir(); - //clear out the syms first - if (Directory.Exists(resurrectee + "/data")) - Directory.Delete(resurrectee + "/data"); - - if (Directory.Exists(resurrectee + "/config")) - Directory.Delete(resurrectee + "/config"); - - if (File.Exists(resurrectee + LibMySQLFile)) - File.Delete(resurrectee + LibMySQLFile); - - Program.DeleteDirectory(resurrectee, true); + Program.DeleteDirectory(resurrectee, true, deleteExcludeList); Directory.CreateDirectory(resurrectee + "/.git/logs"); - CreateSymlink(resurrectee + "/data", StaticDataDir); - CreateSymlink(resurrectee + "/config", StaticConfigDir); - CreateSymlink(resurrectee + LibMySQLFile, StaticDirs + LibMySQLFile); - bool repobusy_check = false; if (!Monitor.TryEnter(RepoLock)) repobusy_check = true; diff --git a/TGServerService/Program.cs b/TGServerService/Program.cs index 96e9721f66..1bf86f3d78 100644 --- a/TGServerService/Program.cs +++ b/TGServerService/Program.cs @@ -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 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 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; } }