-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetPermissions.xql
57 lines (50 loc) · 1.95 KB
/
setPermissions.xql
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
xquery version "3.0";
(: Script based on http://atomic.exist-db.org/blogs/eXist/HoF :)
(:~
: Scan a collection tree recursively starting at $root. Call
: the supplied function once for each resource encountered.
: The first parameter to $func is the collection URI, the
: second the resource path (including the collection part).
:)
declare function local:scan($root as xs:anyURI, $func as
function(xs:anyURI, xs:anyURI?) as item()*) {
local:scan-collections($root, function($collection as xs:anyURI) {
$func($collection, ()),
(: scan-resources expects a function with one parameter, so we use a
partial application
to fill in the collection parameter :)
local:scan-resources($collection, $func($collection, ?))
})
};
(:~
: List all resources contained in a collection and call the
: supplied function once for each resource with the complete
: path to the resource as parameter.
:)
declare function local:scan-resources($collection as xs:anyURI, $func as
function(xs:anyURI) as item()*) {
for $child in xmldb:get-child-resources($collection)
return
$func(xs:anyURI($collection || "/" || $child))
};
(:~
: Scan a collection tree recursively starting at $root. Call
: $func once for each collection found
:)
declare function local:scan-collections($root as xs:anyURI, $func as function
(xs:anyURI) as item()*) {
$func($root),
for $child in xmldb:get-child-collections($root)
return
local:scan-collections(xs:anyURI($root || "/" || $child), $func)
};
let $perms := "g+x,u+x,o+x"
let $dir := local:scan(xs:anyURI("/db/apps/freidi-tools"), function($collection, $resource) {
if ($resource and
xmldb:get-mime-type($resource) = "application/xquery") then
sm:chmod($resource, $perms)
else
sm:chmod($collection, $perms)
})
return
($dir)