Xquery 如何中止和清理不在';不符合规格? 问题是:

Xquery 如何中止和清理不在';不符合规格? 问题是:,xquery,exist-db,Xquery,Exist Db,我有一个重要的应用程序,它不会在默认最小内存配置的exist实例上运行。尽管如此,在安装说明中还是突出显示了这一点。用户不断尝试安装,结果导致实例崩溃。避免让应用程序的用户感到沮丧,并尝试在“RTM!”之外保持阳光灿烂的态度 解决方案(到目前为止) 我这样修改了pre-install.xql,以便在cacheSize或内存低于所需最小值时中止 xquery version "3.0"; import module namespace xdb = "http://exist-db.org/xqu

我有一个重要的应用程序,它不会在默认最小内存配置的exist实例上运行。尽管如此,在安装说明中还是突出显示了这一点。用户不断尝试安装,结果导致实例崩溃。避免让应用程序的用户感到沮丧,并尝试在“RTM!”之外保持阳光灿烂的态度

解决方案(到目前为止) 我这样修改了pre-install.xql,以便在cacheSize或内存低于所需最小值时中止

xquery version "3.0";

import module namespace xdb = "http://exist-db.org/xquery/xmldb";
import module namespace file = "http://exist-db.org/xquery/file" at "java:org.exist.xquery.modules.file.FileModule";

(: 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;

(: the path to the exist-db installation :)
declare variable $exist_home as xs:string := system:get-exist-home();
(:check available memory:)
declare variable $mem-max := system:get-memory-max();
(: minimum memory requirements :)
declare variable $mem-req := 2000000000;
(: minimum cache Size:)
declare variable $cache-req := 500;

declare function local:mkcol-recursive($collection, $components) {
    if (exists($components)) then
        let $newColl := concat($collection, "/", $components[1])
        return
            (
            xdb: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, "/"))
};

(: Helper function to check the instance's chacheSize. :)
declare function local:check-cache-size($path as xs:string) as xs:boolean {
    if (file:is-readable($path || "/conf.xml"))
    then
        (
        let $doc := fn:parse-xml(file:read($path || "/conf.xml"))
        return
            if (number(substring-before($doc//exist/db-connection/@cacheSize/string(), "M")) > $cache-req)
            then
                (fn:true())
            else
                (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:cache-low'), 'Your configured cacheSize is too low')))
    else
        (fn:true())
};

(: Helper function to check the instance's memory. :)
declare function local:check-mem-size($memory as xs:integer) as xs:boolean {
    if ($memory > $mem-req)
    then
        (fn:true())
    else
        (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:memory-low'), 'Your configured -xmx memory is too low'))
};

if (local:check-mem-size($mem-max) and local:check-cache-size($exist_home))
then
    (
    (: store the collection configuration :)
    local:mkcol("/db/system/config", $target),
    xdb:store-files-from-pattern(concat("/db/system/config", $target), $dir, "*.xconf"))
else
    (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:pre-crash'), 'An unknown error occured during pre-install'))
好人 该应用程序会在package manager中产生一个可见的错误,用户不再需要等待20分钟才能看到一般错误和崩溃的实例

meh 该应用程序仍然完全注册到软件包管理器,部分安装后可在该管理器中卸载。它也会出现在仪表板上,但由于它已中止,因此不起作用。应用程序内容部分写入
db/apps/myapp

问题: 是否有更好的方法中止(和撤消)安装?前提是必须通过仪表板的软件包管理器进行安装。我喜欢用户现在看到的自定义错误告诉他们出了什么问题,是否应该将这些错误发送到
控制台:log
?必须在post-install.xql中清除失败的安装,还是可以在pre-install.xql中做得更好?此pre-install.xql中的任何其他明显疏忽

检验 您只需通过eXide创建一个空的exist应用程序,并将默认的pre-install.xql替换为上面的一个。将实例上的
$memreq
更改为成功或出错。下载应用程序并尝试安装

编辑1 根据“[pre-install.xql]将在任何包数据上传到数据库之前执行。”这不是我看到的。数据已上载,这就是当前需要清理的原因。所以这实际上可能是一个bug

编辑2
我尝试了
util:log
fn:trace
的不同组合,然后允许我调用
repo-undeploy()、repo-remove()
进行清理。但我需要
fn:error
实际中止以防止崩溃,并向包管理器报告。所以,是的,功能请求似乎是TWTG。是否有一种方法可以在不使用
fn:error
的情况下将消息记录到package manager中出现错误消息的位置?

听起来似乎是功能请求的一个重要原因-扩展expathrepo代码以读取最低内存/存储要求,阻止安装,并提供适当的警告/指导。或者,它应该被扩展,以提供用于预安装的钩子,以声明安装失败并应恢复。虽然回购代码最近没有得到太多的喜爱,但您可能会建议将其公开。如果你想继续使用应用程序自己的文件,我希望pre-install.xql是你最好的钩子;post-install.xql在文件安装完成之前不会启动。好的,我只是查看了expath repo代码,这可能需要一段时间。我仍然不太理解执行顺序select.xar->begin install->execute pre install->abort(这是否是已注册的安装?在哪里注册)是否存在“安装成功”的最终触发器?将玩一点安装后触发器,看看我是否可以黑客这是一个小清洁的用户。