1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
10 ////////////////////////////////////////////////////////////////////////////////
12 let lastUpdateCount
= 0;
13 let pkgList
= {lmod
:-1};
16 ////////////////////////////////////////////////////////////////////////////////
17 exports
.getPackageList = function () {
18 if (lastUpdateCount
!= pkgList
.lmod
) {
19 pkgList
.lmod
= lastUpdateCount
;
20 pkgList
.list
= pkgDB
.getActivePackages();
21 //for (let pi of pkgList.list) conlog("id=", pi.id, "; name=", pi.name);
27 ////////////////////////////////////////////////////////////////////////////////
31 let queue
= new Array();
34 ////////////////////////////////////////////////////////////////////////////////
35 exports
.__defineGetter__("inProgress", function () (dldr
&& dldr
.running
));
38 ////////////////////////////////////////////////////////////////////////////////
39 exports
.cancel = function () {
41 if (dldr
.running
) dldr
.cancel();
48 ////////////////////////////////////////////////////////////////////////////////
49 function pingQueue () {
50 if (dldr
) return; // in progress
51 let qo
; // queue object
53 if (queue
.length
== 0) return; // nothing to do
56 queue
.splice(0, 1); // remove first element
58 //conlog("NO URL for '", qo.name, "'");
59 // no url: update request; find package
60 let pi
= pkgDB
.getActivePackageByName(qo
.name
);
64 "pi.id=", pi.id, "\n",
65 "pi.name=", pi.name, "\n",
66 "pi.dirname=", pi.dirname, "\n",
67 "pi.version=", pi.version, "\n",
68 "pi.url=", pi.url, "\n"
74 logError("can't update unknown package '"+qo
.name
+"'");
79 //conlog("GS: qo.name=", qo.name, "; qo.url=", qo.url);
81 dldr
= new PkgDownloader(qo
.url
);
83 dldr
.onError = function () {
84 /*++lastUpdateCount;*/
88 dldr
.onCancel = function () {
89 /*++lastUpdateCount;*/
93 dldr
.onComplete = function () {
95 let upd
= pkgDB
.checkAndUpdate(qo
.name
, this.pkg
);
96 conlog((upd
? "" : "NOT "), "UPDATED: '", qo
.name
, "'");
103 dldr
.onMainReceived = function () {
104 let res
= pkgDB
.checkAndUpdate(qo
.name
, this.pkg
, {checkOnly
:true});
105 if (!res
) conlog("package '", qo
.name
, "' is up-to-date");
112 ////////////////////////////////////////////////////////////////////////////////
113 exports
.install = function (name
, url
) {
114 if (typeof(name
) !== "string" || !name
) throw new Error("invalid package name");
115 if (typeof(url
) !== "string" || !(/https?:/.test(url
))) throw new Error("invalid package url");
118 for (let qo
of queue
) {
119 if (qo
.name
== name
) {
120 if (qo
.url
!= url
) throw new Error("conflicting URLs for package '"+name
+"'");
125 if (!found
) queue
.push({name
:name
, url
:url
});
130 ////////////////////////////////////////////////////////////////////////////////
131 exports
.update = function (name
) {
132 if (typeof(name
) !== "string" || !name
) throw new Error("invalid package name");
135 for (let qo
of queue
) {
136 if (qo
.name
== name
) {
141 if (!found
) queue
.push({name
:name
, url
:null});
146 ////////////////////////////////////////////////////////////////////////////////
147 exports
.remove = function (name
) {
148 if (typeof(name
) !== "string" || !name
) throw new Error("invalid package name");
149 if (dldr
&& dldr
.running
) throw new Error("package manager is busy");
151 pkgDB
.removePackage(name
);
152 conlog("package '", name
, "' removed");
153 } catch (e
) { logException("WTF", e
); }