-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathgetfaclwdx.lua
85 lines (77 loc) · 2.77 KB
/
getfaclwdx.lua
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- requires getfacl
local cmd = "getfacl"
local params = "-E"
local separator = ", "
local nocut = false
local skipsysfiles = true -- skip character, block or fifo files
local output = ''
local filename = ''
local fields = {
{"User", "\nuser::([^\n]+)", false},
{"Users", "\nuser:([^\n]+)", true},
{"Default User", "\ndefault:user::([^\n]+)", false},
{"Default Users", "\ndefault:user:([^\n]+)", true},
{"Group", "\ngroup::([^\n]+)", false},
{"Groups", "\ngroup:([^\n]+)", true},
{"Default Group", "\ndefault:group::([^\n]+)", false},
{"Default Groups", "\ndefault:group:([^\n]+)", true},
{"Mask", "\nmask::([^\n]+)", false},
{"Default Mask", "\ndefault:mask::([^\n]+)", false},
{"Other", "\nother::([^\n]+)", false},
{"Default Other", "\ndefault:other::([^\n]+)", false},
{"Flags", "\n%#%sflags:%s([^\n]+)", false},
{"Owner Name", "\n%#%sowner:%s([^\n]+)", false},
{"Group Name", "\n%#%sgroup:%s([^\n]+)", false},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil) then
return fields[FieldIndex + 1][1], "", 8;
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetDefaultSortOrder(FieldIndex)
return 1; --or -1
end
function ContentGetDetectString()
return 'EXT="*"'; -- return detect string
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
local delimpat = SysUtils.PathDelim;
if (delimpat == nil) then
delimpat = "/\\";
end
if (FileName:find("[" .. delimpat .. "]%.%.$")) then
return nil;
end
if (filename ~= FileName) then
if (skipsysfiles == true) then
local attr = SysUtils.FileGetAttr(FileName);
if (attr < 0) or (math.floor(attr / 0x00000004) % 2 ~= 0) then
return nil;
end
end
local handle = io.popen(cmd .. ' ' .. params .. ' "' .. FileName:gsub('"', '\\"') .. '"');
output = handle:read("*a");
handle:close();
filename = FileName;
end
if (fields[FieldIndex + 1][2] ~= nil) and (fields[FieldIndex + 1][3] ~= nil) then
return getvalue(fields[FieldIndex + 1][2], fields[FieldIndex + 1][3]);
end
return nil;
end
function getvalue(pattern, multi)
local resultstr = '';
if (multi == true) then
for str in output:gmatch(pattern) do
if (resultstr ~= '') then
resultstr = resultstr .. separator .. str;
elseif (str:sub(1, 1) ~= ":") or (nocut == true) then
resultstr = str;
end
end
else
resultstr = output:match(pattern);
end
return resultstr;
end