mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 06:27:19 +01:00
Revert "Merge pull request #349 from Cyberboss/FileCopyDeleteSpeedup"
This reverts commit448e155e7c, reversing changes made toe91aa90452.
This commit is contained in:
+16
-26
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TGS.Server
|
||||
{
|
||||
@@ -33,7 +32,7 @@ namespace TGS.Server
|
||||
/// <param name="path">The directory to delete</param>
|
||||
/// <param name="ContentsOnly">If <see langword="true"/>, an empty <paramref name="path"/> will remain instead of being deleted fully. Incompatible with <paramref name="excludeRoot"/></param>
|
||||
/// <param name="excludeRoot">If any files or directories in the root level of <paramref name="path"/> match anything in this <see cref="IList{T}"/> of <see cref="string"/>s, they won't be deleted. Incompatible with <paramref name="ContentsOnly"/></param>
|
||||
public static async void DeleteDirectory(string path, bool ContentsOnly = false, IList<string> excludeRoot = null)
|
||||
public static void DeleteDirectory(string path, bool ContentsOnly = false, IList<string> excludeRoot = null)
|
||||
{
|
||||
var di = new DirectoryInfo(path);
|
||||
if (!di.Exists)
|
||||
@@ -43,7 +42,7 @@ namespace TGS.Server
|
||||
excludeRoot[I] = excludeRoot[I].ToLower();
|
||||
if (CheckDeleteSymlinkDir(di))
|
||||
return;
|
||||
await NormalizeAndDelete(di, excludeRoot, false);
|
||||
NormalizeAndDelete(di, excludeRoot);
|
||||
if (!ContentsOnly)
|
||||
{
|
||||
if (excludeRoot != null && excludeRoot.Count > 0)
|
||||
@@ -73,31 +72,24 @@ namespace TGS.Server
|
||||
/// </summary>
|
||||
/// <param name="dir"><see cref="DirectoryInfo"/> of the directory to empty</param>
|
||||
/// <param name="excludeRoot">Lowercase file and directory names to skip while emptying this level. Not passed forward</param>
|
||||
/// <param name="deleteRoot">If <see langword="true"/>, <paramref name="dir"/> will be deleted before the function exits</param>
|
||||
static async Task NormalizeAndDelete(DirectoryInfo dir, IList<string> excludeRoot, bool deleteRoot)
|
||||
static void NormalizeAndDelete(DirectoryInfo dir, IList<string> excludeRoot)
|
||||
{
|
||||
var tasks = new List<Task> { Task.Factory.StartNew(() =>
|
||||
{
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
if (excludeRoot != null && excludeRoot.Contains(file.Name.ToLower()))
|
||||
continue;
|
||||
file.Attributes = FileAttributes.Normal;
|
||||
file.Delete();
|
||||
}
|
||||
}) };
|
||||
|
||||
foreach (var subDir in dir.GetDirectories())
|
||||
{
|
||||
if (excludeRoot != null && excludeRoot.Contains(subDir.Name.ToLower()))
|
||||
continue;
|
||||
if (CheckDeleteSymlinkDir(subDir))
|
||||
continue;
|
||||
tasks.Add(NormalizeAndDelete(subDir, null, true));
|
||||
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;
|
||||
file.Delete();
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
if(deleteRoot)
|
||||
dir.Delete(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,7 +99,7 @@ namespace TGS.Server
|
||||
/// <param name="destDirName">The destination directory</param>
|
||||
/// <param name="ignore">List of files and directories to ignore while copying</param>
|
||||
/// <param name="ignoreIfNotExists">If <see langword="true"/> no error will be thrown if <paramref name="sourceDirName"/> does not exist</param>
|
||||
public static async void CopyDirectory(string sourceDirName, string destDirName, IList<string> ignore = null, bool ignoreIfNotExists = false)
|
||||
public static void CopyDirectory(string sourceDirName, string destDirName, IList<string> ignore = null, bool ignoreIfNotExists = false)
|
||||
{
|
||||
IList<string> realIgnore;
|
||||
if (ignore != null)
|
||||
@@ -118,7 +110,7 @@ namespace TGS.Server
|
||||
}
|
||||
else
|
||||
realIgnore = null;
|
||||
await CopyDirectoryImpl(sourceDirName, destDirName, realIgnore, ignoreIfNotExists);
|
||||
CopyDirectoryImpl(sourceDirName, destDirName, realIgnore, ignoreIfNotExists);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -128,7 +120,7 @@ namespace TGS.Server
|
||||
/// <param name="destDirName">The destination directory</param>
|
||||
/// <param name="ignore">List of lowercase files and directories to ignore while copying</param>
|
||||
/// <param name="ignoreIfNotExists">If <see langword="true"/> no error will be thrown if <paramref name="sourceDirName"/> does not exist</param>
|
||||
static async Task CopyDirectoryImpl(string sourceDirName, string destDirName, IList<string> ignore, bool ignoreIfNotExists) {
|
||||
static void CopyDirectoryImpl(string sourceDirName, string destDirName, IList<string> ignore, bool ignoreIfNotExists) {
|
||||
// If the destination directory doesn't exist, create it.
|
||||
if (!Directory.Exists(destDirName))
|
||||
{
|
||||
@@ -158,16 +150,14 @@ namespace TGS.Server
|
||||
file.CopyTo(temppath, true);
|
||||
}
|
||||
|
||||
var tasks = new List<Task>();
|
||||
// copy them and their contents to new location.
|
||||
foreach (DirectoryInfo subdir in dirs)
|
||||
{
|
||||
if (ignore != null && ignore.Contains(subdir.Name.ToLower()))
|
||||
continue;
|
||||
string temppath = Path.Combine(destDirName, subdir.Name);
|
||||
tasks.Add(CopyDirectoryImpl(subdir.FullName, temppath, ignore, false));
|
||||
CopyDirectoryImpl(subdir.FullName, temppath, ignore, false);
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user