mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-31 00:50:45 +01:00
Fix directory deletion not checking the root path is a symlink
This commit is contained in:
@@ -30,15 +30,17 @@ namespace Tgstation.Server.Host.IO
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
|
||||
// check if we are a symbolic link
|
||||
if (!dir.Attributes.HasFlag(FileAttributes.Directory) || dir.Attributes.HasFlag(FileAttributes.ReparsePoint))
|
||||
{
|
||||
dir.Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var subDir in dir.EnumerateDirectories())
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// if below succeeds this is probably a symlink
|
||||
if (!subDir.Attributes.HasFlag(FileAttributes.Directory) || subDir.Attributes.HasFlag(FileAttributes.ReparsePoint))
|
||||
subDir.Delete();
|
||||
else
|
||||
tasks.Add(NormalizeAndDelete(subDir, cancellationToken));
|
||||
tasks.Add(NormalizeAndDelete(subDir, cancellationToken));
|
||||
}
|
||||
|
||||
foreach (var file in dir.EnumerateFiles())
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Tgstation.Server.Host.IO
|
||||
Task CreateDirectory(string path, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Recursively delete a directory
|
||||
/// Recursively delete a directory, removes and does not enter any symlinks encounterd.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the directory to delete</param>
|
||||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for the operation</param>
|
||||
|
||||
Reference in New Issue
Block a user