-
Notifications
You must be signed in to change notification settings - Fork 24
/
getfattrcustomwdx.lua
59 lines (52 loc) · 1.57 KB
/
getfattrcustomwdx.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
-- getfattrcustomwdx.lua
-- 2020.08.05
--[[
Get custom extended attributes. Requires getfattr.
For Unix-like only!
"User defined attribute" returns value of custom extended attribute by name.
See (and edit) list of name these attributes in the "un" table.
"All extended attributes" returns list of all custom extended attributes
(will be separate by semicolon and space, i.e. "; ").
]]
local un = {
"comment",
"target",
"type"
}
function ContentGetSupportedField(FieldIndex)
if FieldIndex == 0 then
return "User defined attribute", table.concat(un, '|'), 8
elseif FieldIndex == 1 then
return "All extended attributes", "", 8
end
return "", "", 0
end
function ContentGetDefaultSortOrder(FieldIndex)
return 1; --or -1
end
function ContentGetDetectString()
return 'EXT="*"'
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if FieldIndex > 1 then return nil end
local h = io.popen('getfattr --dump --encoding=text --no-dereference --absolute-names "' .. FileName:gsub('"', '\\"') .. '"')
if h == nil then return nil end
local out = h:read('*a')
h:close()
if (out ~= nil) and (out ~= '') then
local s = ''
if FieldIndex == 0 then
if un[UnitIndex + 1] ~= nil then
s = string.match(out, 'user%.' .. un[UnitIndex + 1] .. '="([^"]+)"')
if (s ~= nil) and (s ~= '') then return s end
end
elseif FieldIndex == 1 then
for l in string.gmatch(out, 'user%.([^=]+)=') do
s = s .. '; ' .. l
end
s = string.sub(s, 3, -1)
if string.len(s) > 0 then return s end
end
end
return nil
end