mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 14:06:41 +01:00
Merge pull request #286 from tgstation/Cyberboss-patch-3
Fixes recursive symlink deletion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
@@ -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,22 @@ namespace TGServerService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Properly unlinks directory <paramref name="di"/> if it is a symlink
|
||||
/// </summary>
|
||||
/// <param name="di"><see cref="DirectoryInfo"/> for the directory in question</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="di"/> was a symlink and deleted, <see langword="false"/> otherwise</returns>
|
||||
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 +80,8 @@ namespace TGServerService
|
||||
{
|
||||
if (excludeRoot != null && excludeRoot.Contains(subDir.Name.ToLower()))
|
||||
continue;
|
||||
if (CheckDeleteSymlinkDir(subDir))
|
||||
continue;
|
||||
NormalizeAndDelete(subDir, null);
|
||||
subDir.Delete(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user