forked from eXist-db/public-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-install.xql
57 lines (49 loc) · 2.13 KB
/
post-install.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";
import module namespace scanrepo="http://exist-db.org/xquery/admin/scanrepo" at "modules/scan.xql";
import module namespace system="http://exist-db.org/xquery/system";
import module namespace util="http://exist-db.org/xquery/util";
import module namespace xdb="http://exist-db.org/xquery/xmldb";
(: The following external variables are set by the repo:deploy function :)
(: file path pointing to the exist installation directory :)
declare variable $home external;
(: path to the directory containing the unpacked .xar package :)
declare variable $dir external;
(: the target collection into which the app is deployed :)
declare variable $target external;
declare function local:mkcol-recursive($collection, $components) {
if (exists($components)) then
let $newColl := concat($collection, "/", $components[1])
return (
xmldb:create-collection($collection, $components[1]),
local:mkcol-recursive($newColl, subsequence($components, 2))
)
else
()
};
(: Helper function to recursively create a collection hierarchy. :)
declare function local:mkcol($collection, $path) {
local:mkcol-recursive($collection, tokenize($path, "/"))
};
declare function local:get-repo-dir() {
let $home := system:get-exist-home()
let $pathSep := util:system-property("file.separator")
return
if (doc-available(concat("file:///", $home, "/webapp/repo/packages"))) then
concat($home, "/webapp/repo/packages")
else if(ends-with($home, "WEB-INF")) then
concat(substring-before($home, "WEB-INF"), "/repo/packages")
else
concat($home, $pathSep, "/webapp/repo/packages")
};
declare function local:copy-previous-public-from-temp-or-create() {
if (xmldb:collection-available("/db/temp/public")) then
let $copy-dummy := xmldb:copy("/db/temp/public", $target)
return xmldb:remove("/db/temp/public")
else
local:mkcol($target, "public")
};
system:as-user("repo", "repo", (
local:copy-previous-public-from-temp-or-create(),
xmldb:store-files-from-pattern(concat($target, "/public"), local:get-repo-dir(), "*.xar"),
scanrepo:scan()
))