diff --git a/modules/db-utility.xqm b/modules/db-utility.xqm index 108dce8..f93983f 100644 --- a/modules/db-utility.xqm +++ b/modules/db-utility.xqm @@ -20,7 +20,7 @@ function dbu:ensure-collection($path as xs:string) as xs:string { then $path else tokenize($path, "/") - => tail() + => tail() => fold-left("", dbu:create-collection-with-repo-permissions#2) }; @@ -39,7 +39,7 @@ function dbu:ensure-collection($path as xs:string, $permissions as map(*)) as xs then $path else tokenize($path, "/") - => tail() + => tail() => fold-left("", dbu:create-collection(?, ?, $permissions)) }; @@ -50,7 +50,7 @@ function dbu:ensure-collection($path as xs:string, $permissions as map(*)) as xs : @param $resource-or-collection xs:string : @returns the path that was entered :) -declare +declare function dbu:set-repo-permissions ($resource-or-collection as xs:string) as xs:string { dbu:set-permissions($resource-or-collection, $dbu:default-permissions) }; @@ -63,15 +63,15 @@ function dbu:set-repo-permissions ($resource-or-collection as xs:string) as xs:s : @param $permissions map(xs:string, xs:string) with "owner", "group", "mode" : @returns the path that was entered :) -declare +declare function dbu:set-permissions ($resource-or-collection as xs:string, $permissions as map(*)) as xs:string { - sm:chown($resource-or-collection, $permissions?owner), - sm:chgrp($resource-or-collection, $permissions?group), + sm:chown(xs:anyURI($resource-or-collection), $permissions?owner), + sm:chgrp(xs:anyURI($resource-or-collection), $permissions?group), sm:chmod(xs:anyURI($resource-or-collection), $permissions?mode), $resource-or-collection }; -declare +declare %private function dbu:create-collection-with-repo-permissions ($collection as xs:string, $next as xs:string) as xs:string { if (xmldb:collection-available(concat($collection, '/', $next))) @@ -82,7 +82,7 @@ function dbu:create-collection-with-repo-permissions ($collection as xs:string, }; -declare +declare %private function dbu:create-collection ($collection as xs:string, $next as xs:string, $permissions as map(*)) as xs:string { if (xmldb:collection-available(concat($collection, '/', $next))) diff --git a/modules/scan.xqm b/modules/scan.xqm index 18b2fec..fabb17b 100644 --- a/modules/scan.xqm +++ b/modules/scan.xqm @@ -23,8 +23,8 @@ declare namespace expath="http://expath.org/ns/pkg"; declare function scanrepo:store($collection-uri as xs:string, $resource-name as xs:string, $contents as item()?) as xs:string { xmldb:store($collection-uri, $resource-name, $contents) ! ( - sm:chgrp(., config:repo-permissions()?group), - sm:chmod(., config:repo-permissions()?mode), + sm:chgrp(xs:anyURI(.), config:repo-permissions()?group), + sm:chmod(xs:anyURI(.), config:repo-permissions()?mode), . ) }; @@ -32,7 +32,7 @@ declare function scanrepo:store($collection-uri as xs:string, $resource-name as (:~ : Helper function to store a package's icon and transform its metadata into the format needed for raw-metadata :) -declare +declare %private function scanrepo:handle-icon($path as xs:string, $data as item()?, $param as item()*) as element(icon) { let $pkgName := substring-before($param, ".xar") @@ -46,20 +46,20 @@ function scanrepo:handle-icon($path as xs:string, $data as item()?, $param as it (:~ : Helper function to transform expath-pkg.xml metadata into the format needed for raw-metadata :) -declare +declare %private function scanrepo:handle-expath-pkg-metadata($root as element(expath:package)) as element()* { - $root/(@name, expath:title, @abbrev, @version) ! + $root/(@name, expath:title, @abbrev, @version) ! element { local-name(.) } { ./string() }, - $root/expath:dependency[@processor eq $config:exist-processor-name] ! + $root/expath:dependency[@processor eq $config:exist-processor-name] ! element requires { ./@* } }; (:~ : Helper function to transform repo.xml's changelog metadata into the format needed for raw-metadata :) -declare - %private +declare + %private function scanrepo:copy-changelog($nodes as node()*) { for $node in $nodes return @@ -76,10 +76,10 @@ function scanrepo:copy-changelog($nodes as node()*) { (:~ : Helper function to transform repo.xml metadata into the format needed for raw-metadata :) -declare +declare %private function scanrepo:handle-repo-metadata($root as element(repo:meta)) as element()+ { - $root/(repo:author, repo:description, repo:website, repo:license, repo:type, repo:note) ! + $root/(repo:author, repo:description, repo:website, repo:license, repo:type, repo:note) ! element { local-name(.) } { ./string() }, element changelog { scanrepo:copy-changelog($root/repo:changelog/repo:change) } }; @@ -87,11 +87,11 @@ function scanrepo:handle-repo-metadata($root as element(repo:meta)) as element() (:~ : Helper function to handle transformation of icon and package metadata for extraction from the xar :) -declare +declare %private function scanrepo:entry-data($path as xs:anyURI, $type as xs:string, $data as item()?, $param as item()*) as item()* { - if (starts-with($path, "icon")) then + if (starts-with($path, "icon")) then scanrepo:handle-icon($path, $data, $param) else let $root := $data/* @@ -108,8 +108,8 @@ function scanrepo:entry-data($path as xs:anyURI, $type as xs:string, $data as it (:~ : Helper function to select assets from a package for extraction from the xar :) -declare - %private +declare + %private function scanrepo:entry-filter($path as xs:anyURI, $type as xs:string, $param as item()*) as xs:boolean { starts-with($path, "icon.") or $path = ("repo.xml", "expath-pkg.xml") }; @@ -117,7 +117,7 @@ function scanrepo:entry-filter($path as xs:anyURI, $type as xs:string, $param as (:~ : Take a group of packages with the same package name (a URI) and generate a package-group :) -declare +declare (: %private:) function scanrepo:generate-package-group($packages as element(package)*) { if (count(distinct-values($packages/name)) gt 1) then @@ -125,13 +125,13 @@ function scanrepo:generate-package-group($packages as element(package)*) { else (: Identify newest version of the package; sort previous versions newest to oldest; use SemVer 2.0 rules, coercing where needed :) let $versions := $packages/version - let $version-maps := + let $version-maps := $versions ! map:merge(( - map:entry("semver", semver:parse(., true()) => semver:serialize()), + map:entry("semver", semver:parse(., true()) => semver:serialize()), map:entry("version", .) )) let $sorted-semvers := semver:sort($version-maps?semver) => reverse() - let $sorted-packages := + let $sorted-packages := for $semver in $sorted-semvers return $version-maps[?semver eq $semver]?version/.. @@ -139,7 +139,7 @@ function scanrepo:generate-package-group($packages as element(package)*) { let $legacy-abbrevs := distinct-values($packages/abbrev)[not(. = $newest-package/abbrev)] return element package-group { - $newest-package/(title, name, abbrev), + $newest-package/(title, name, abbrev), $legacy-abbrevs ! element abbrev { attribute type { "legacy" }, . }, element packages { $sorted-packages } } @@ -155,9 +155,9 @@ declare function scanrepo:update-package-group($raw-package-name as xs:string) { let $package-groups := doc($config:package-groups-doc)/package-groups let $current-package-group := $package-groups/package-group[name eq $raw-package-name] return - if (exists($current-package-group)) then - update replace $current-package-group with scanrepo:generate-package-group($raw-packages-to-group) - else + if (exists($current-package-group)) then + update replace $current-package-group with scanrepo:generate-package-group($raw-packages-to-group) + else update insert scanrepo:generate-package-group($raw-packages-to-group) into $package-groups }; @@ -168,9 +168,9 @@ declare function scanrepo:add-raw-package($raw-package as element(package)) { let $raw-packages := doc($config:raw-packages-doc)/raw-packages let $current-raw-package := $raw-packages/package[@path = $raw-package/@path] return - if (exists($current-raw-package)) then + if (exists($current-raw-package)) then update replace $current-raw-package with $raw-package - else + else update insert $raw-package into $raw-packages }; @@ -183,7 +183,7 @@ declare function scanrepo:extract-raw-package($xar-filename as xs:string) as ele let $package-metadata := compression:unzip( $xar-binary, - scanrepo:entry-filter#3, + scanrepo:entry-filter#3, (), scanrepo:entry-data#4, $xar-filename @@ -218,8 +218,8 @@ declare function scanrepo:rebuild-package-groups() as xs:string { group by $name := $package/name return scanrepo:generate-package-group($package) - let $package-groups := - element package-groups { + let $package-groups := + element package-groups { for $group in $groups order by $group/abbrev[not(@type = "legacy")] return @@ -233,8 +233,8 @@ declare function scanrepo:rebuild-package-groups() as xs:string { : Rebuild the raw-packages metadata from all stored packages :) declare function scanrepo:rebuild-raw-packages() as xs:string { - let $raw-packages := - element raw-packages { + let $raw-packages := + element raw-packages { for $package-xar in xmldb:get-child-resources($config:packages-col)[ends-with(., ".xar")] order by $package-xar collation "http://www.w3.org/2013/collation/UCA?numeric=yes" return diff --git a/post-install.xq b/post-install.xq index f7f100a..29fd189 100644 --- a/post-install.xq +++ b/post-install.xq @@ -2,11 +2,11 @@ xquery version "3.1"; (:~ : This post-install script sets permissions on the package data collection hierarchy. - : When pre-install creates the public-repo-data collection, its permissions are admin/dba. + : When pre-install creates the public-repo-data collection, its permissions are admin/dba. : This ensures the collections are owned by the default user and group for the app. : The script also builds the package metadata if it doesn't already exist. :) - + import module namespace config="http://exist-db.org/xquery/apps/config" at "modules/config.xqm"; import module namespace dbu="http://exist-db.org/xquery/utility/db" at "modules/db-utility.xqm"; import module namespace scanrepo="http://exist-db.org/xquery/admin/scanrepo" at "modules/scan.xqm"; @@ -25,7 +25,7 @@ declare variable $dir external; declare variable $target external; (: Configuration file for the logs collection :) -declare variable $logs-xconf := +declare variable $logs-xconf := @@ -60,7 +60,7 @@ xmldb:reindex($config:logs-col), if (doc-available($config:raw-packages-doc) and doc-available($config:package-groups-doc)) then () else - scanrepo:rebuild-all-package-metadata() ! sm:chown(., config:repo-permissions()?owner), - + scanrepo:rebuild-all-package-metadata() ! sm:chown(xs:anyURI(.), config:repo-permissions()?owner), + (: Ensure get-package.xq is run as "repo:repo", so that logs will always be writable :) sm:chmod(xs:anyURI($target || "/modules/get-package.xq"), "rwsr-sr-x")