-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathDelete.Windows.cs
More file actions
64 lines (53 loc) · 2.73 KB
/
Delete.Windows.cs
File metadata and controls
64 lines (53 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text;
using Xunit;
using Microsoft.DotNet.XUnitExtensions;
using System.Security.Principal;
using System.Security.AccessControl;
namespace System.IO.Tests
{
public partial class Directory_Delete_str_bool : Directory_Delete_str
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void RecursiveDelete_DirectoryContainingJunction()
{
// Junctions (NTFS directory junctions) share the IO_REPARSE_TAG_MOUNT_POINT reparse
// tag with volume mount points, but DeleteVolumeMountPoint only works for volume mount
// points. Ensure that recursive delete succeeds when the directory contains a junction.
string target = GetTestFilePath();
Directory.CreateDirectory(target);
string linkParent = GetTestFilePath();
Directory.CreateDirectory(linkParent);
string junctionPath = Path.Combine(linkParent, GetTestFileName());
Assert.True(MountHelper.CreateJunction(junctionPath, target));
// Both the junction and the target exist before deletion
Assert.True(Directory.Exists(junctionPath), "junction should exist before delete");
Assert.True(Directory.Exists(target), "target should exist before delete");
// Recursive delete of the parent should succeed and remove the junction without following it
Delete(linkParent, recursive: true);
Assert.False(Directory.Exists(linkParent), "parent should be deleted");
Assert.True(Directory.Exists(target), "target should still exist after deleting junction");
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void RecursiveDelete_NoListDirectoryPermission() // https://github.com/dotnet/runtime/issues/56922
{
using WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
string parentPath = GetTestFilePath();
var parent = Directory.CreateDirectory(parentPath);
var ac = parent.GetAccessControl();
var rule = new FileSystemAccessRule(currentIdentity.User, FileSystemRights.ListDirectory, AccessControlType.Deny);
ac.SetAccessRule(rule);
parent.SetAccessControl(ac);
var subDir = parent.CreateSubdirectory("subdir");
File.Create(Path.Combine(subDir.FullName, GetTestFileName())).Dispose();
Delete(subDir.FullName, recursive: true);
Assert.False(subDir.Exists);
// Cleanup
ac.RemoveAccessRule(rule);
parent.SetAccessControl(ac);
}
}
}