forked from gordon-matt/elFinder.NetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIFileExtensions.cs
More file actions
57 lines (47 loc) · 1.69 KB
/
Copy pathIFileExtensions.cs
File metadata and controls
57 lines (47 loc) · 1.69 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
using elFinder.NetCore.Drivers;
namespace elFinder.NetCore.Extensions;
public static class IFileExtensions
{
public static byte GetLockedFlag(this IFile file, RootVolume volume)
{
if (volume.IsLocked)
{
return 1;
}
return GetFlag(file, volume, x => x.Locked);
}
public static byte GetReadFlag(this IFile file, RootVolume volume)
{
return GetFlag(file, volume, x => x.Read);
}
public static byte GetWriteFlag(this IFile file, RootVolume volume)
{
if (volume.IsReadOnly)
{
return 0;
}
return GetFlag(file, volume, x => x.Write);
}
private static byte GetFlag(this IFile file, RootVolume volume, Func<AccessControlAttributeSet, bool> fieldSelector)
{
if (volume.AccessControlAttributes != null)
{
var attributeSet = volume.AccessControlAttributes.FirstOrDefault(x => x.FullName == file.FullName);
if (attributeSet != null)
{
return fieldSelector(attributeSet) ? (byte)1 : (byte)0;
}
var parentDirectory = file.Directory;
while (parentDirectory != null && parentDirectory.FullName != volume.RootDirectory)
{
attributeSet = volume.AccessControlAttributes.FirstOrDefault(x => x.FullName == parentDirectory.FullName);
if (attributeSet != null)
{
return fieldSelector(attributeSet) ? (byte)1 : (byte)0;
}
parentDirectory = parentDirectory.Parent;
}
}
return fieldSelector(volume.DefaultAccessControlAttributes) ? (byte)1 : (byte)0;
}
}