joewiz
8/11/2016 - 6:39 PM

Make XQuery modules executable

Make XQuery modules executable

xquery version "3.1";

import module namespace console="http://exist-db.org/xquery/console" at "java:org.exist.console.xquery.ConsoleModule";
import module namespace dbutil="http://exist-db.org/xquery/dbutil" at "/db/apps/shared-resources/content/dbutils.xql";

(: Uses dbutil to recurse through a collection and make xquery files executable.
 : Based on http://atomic.exist-db.org/blogs/eXist/HoF but updated for eXist-db 3.0.
 : Imported console module requires monex to be installed. :)

let $collection := "/db/apps/release"
let $perms := "g+x,u+x,o+x"
return
    dbutil:scan(xs:anyURI($collection), function($collection, $resource) {
        if ($resource and xmldb:get-mime-type($resource) = "application/xquery") then
            (
                sm:chmod($resource, $perms)
                ,
                console:log('fixed ' || $resource)
            )
        else
            sm:chmod($collection, $perms)
    })