Skip to content

Commit 46df57c

Browse files
committed
Create collections & xconf during post-install
At the time pre-install runs, no resources have been stored in the database, so we can’t easily read from repo.xml to find the default permissions info. However, at the time post-install runs, these resources are present. (Assuming eXist-db/exist#3734 is closed, that is.) Thus, we will move all setup of public-repo-data collections to post-install.xql.
1 parent ffc8a2d commit 46df57c

File tree

3 files changed

+48
-100
lines changed

3 files changed

+48
-100
lines changed

post-install.xq

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,60 @@ declare variable $dir external;
2323
(: the target collection into which the app is deployed :)
2424
declare variable $target external;
2525

26-
(: Until https://github.com/eXist-db/exist/issues/3734 is fixed, we hard code the default group name :)
27-
declare variable $repo-group :=
28-
(: config:repo-permissions()?group :)
29-
"repo"
30-
;
31-
declare variable $repo-user :=
32-
(: config:repo-permissions()?user :)
33-
"repo"
34-
;
26+
(: Configuration file for the logs collection :)
27+
declare variable $logs-xconf :=
28+
<collection xmlns="http://exist-db.org/collection-config/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
29+
<index>
30+
<range>
31+
<create qname="type" type="xs:string"/>
32+
</range>
33+
</index>
34+
</collection>;
35+
36+
(: Helper function to recursively create a collection hierarchy :)
37+
declare function local:mkcol-recursive($collection as xs:string, $components as xs:string*) {
38+
if (exists($components)) then
39+
let $newColl := concat($collection, "/", $components[1])
40+
return (
41+
xmldb:create-collection($collection, $components[1]),
42+
local:mkcol-recursive($newColl, subsequence($components, 2))
43+
)
44+
else
45+
()
46+
};
47+
48+
(: Create a collection hierarchy :)
49+
declare function local:mkcol($collection as xs:string, $path as xs:string) {
50+
local:mkcol-recursive($collection, tokenize($path, "/"))
51+
};
3552

3653
(:~
3754
: Set user and group to be owner by values in repo.xml
3855
:)
3956
declare function local:set-data-collection-permissions($resource as xs:string) {
40-
if (sm:get-permissions(xs:anyURI($resource))/sm:permission/@group = $repo-group) then
57+
if (sm:get-permissions(xs:anyURI($resource))/sm:permission/@group = config:repo-permissions()?group) then
4158
()
4259
else
4360
(
44-
sm:chown($resource, $repo-user),
45-
sm:chgrp($resource, $repo-group),
46-
sm:chmod(xs:anyURI($resource), "rwxrwxr-x")
61+
sm:chown($resource, config:repo-permissions()?user),
62+
sm:chgrp($resource, config:repo-permissions()?group),
63+
sm:chmod(xs:anyURI($resource), config:repo-permissions()?mode)
4764
)
4865
};
4966

67+
(: Create the data collection hierarchy :)
68+
69+
xmldb:create-collection($config:app-data-parent-col, $config:app-data-col-name),
70+
for $col-name in ($config:icons-col-name, $config:metadata-col-name, $config:packages-col-name, $config:logs-col-name)
71+
return
72+
xmldb:create-collection($config:app-data-col, $col-name),
73+
74+
(: Create log indexes :)
75+
76+
local:mkcol("/db/system/config", $config:logs-col),
77+
xmldb:store("/db/system/config" || $config:logs-col, "collection.xconf", $logs-xconf),
78+
xmldb:reindex($config:logs-col),
79+
5080
(: Set user and group ownership on the package data collection hierarchy :)
5181

5282
for $col in ($config:app-data-col, xmldb:get-child-collections($config:app-data-col) ! ($config:app-data-col || "/" || .))
@@ -58,10 +88,8 @@ return
5888
if (doc-available($config:raw-packages-doc) and doc-available($config:package-groups-doc)) then
5989
()
6090
else
61-
(
62-
scanrepo:rebuild-all-package-metadata(),
63-
($config:raw-packages-doc, $config:package-groups-doc) ! local:set-data-collection-permissions(.)
64-
),
91+
scanrepo:rebuild-all-package-metadata(),
6592

66-
(: execute get-package.xq as repo group, so that it can write to logs :)
67-
sm:chmod(xs:anyURI($target || "/modules/get-package.xq"), "rwsrwxr-x")
93+
(: Ensure get-package.xq is run as "repo" group, so that it can write to logs :)
94+
95+
sm:chmod(xs:anyURI($target || "/modules/get-package.xq"), "g+s")

pre-install.xq

Lines changed: 0 additions & 80 deletions
This file was deleted.

repo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<copyright>true</copyright>
99
<type>application</type>
1010
<target>public-repo</target>
11-
<prepare>pre-install.xq</prepare>
11+
<prepare/>
1212
<finish>post-install.xq</finish>
1313
<permissions password="repo" user="repo" group="repo" mode="rwxrwxr-x"/>
1414
<changelog>

0 commit comments

Comments
 (0)