[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 9/9] lpt: upgrade um ein einzelnes Paket zu aktualisieren



+ lpt: upgrade um ein einzelnes Paket zu aktualisieren

Signed-off-by: Antoine Kaufmann <toni@xxxxxxxxxx>
---
 src/modules/pas/lpt/lang/lang_en.c |    1 +
 src/modules/pas/lpt/lpt.pas        |   57 ++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/src/modules/pas/lpt/lang/lang_en.c b/src/modules/pas/lpt/lang/lang_en.c
index 3c45acf..684aa87 100644
--- a/src/modules/pas/lpt/lang/lang_en.c
+++ b/src/modules/pas/lpt/lang/lang_en.c
@@ -64,6 +64,7 @@ static const struct tms_strings dict[] = {
     "  install: Install a package from a local file\n"
     "           (speficy file name as last parameter)\n"
     "  remove:  Remove a package\n"
+    "  upgrade: Upgrade the specified package\n"
     "  upgrade-all: Upgrade all installed packages",
 
     // Herunterladen und Entpacken von %s
diff --git a/src/modules/pas/lpt/lpt.pas b/src/modules/pas/lpt/lpt.pas
index 97da589..43cfe19 100644
--- a/src/modules/pas/lpt/lpt.pas
+++ b/src/modules/pas/lpt/lpt.pas
@@ -14,6 +14,7 @@ resourcestring
         '  install: Installiert das angegebene Paket aus lokaler Datei'#10 +
         '           Achtung, Datei als letzten Parameter angeben!'#10 +
         '  remove: Paket deinstallieren'#10 +
+        '  upgrade: Das angegebene Paket aktualisieren'#10 +
         '  upgrade-all: Alle installierten Pakete aktualisieren';
 
     rsDownloadAndExtract = 'Herunterladen und Entpacken von %s';
@@ -458,6 +459,55 @@ begin
 end;
 
 (**
+ * Paket aktualisieren (nur neuste Version)
+ *
+ * @param name Paketname
+ *)
+procedure Upgrade(name: String);
+var
+    pkgset, installed: TPackageSet;
+    pkg: TPackage;
+    ver: TPackageVersion;
+    verRepo: TPackageVersion;
+    i: Integer;
+    sectname: String;
+
+begin
+    pkgset := TPackageSet.create;
+    installed := TPackageSet.create;
+
+    FindInstalledPackages(installed);
+    ReadPkgsrc(getConfigRoot + 'pkgsrc');
+    ReadPkglists(pkgset);
+
+    (* Section aus dem Paketnamen extrahieren, falls angegeben *)
+    sectname := 'bin';
+    i := Pos(name, '/');
+    if i > 0 then begin
+        sectname := Copy(name, i + 1, Length(name));
+        sectname := Copy(name, 1, i - 1);
+    end;
+
+    ver := installed.GetCurrentVersion(name, sectname);
+    if ver = nil then begin
+        WriteLn(rsNotInstalled);
+        Exit;
+    end;
+
+    verRepo := pkgset.GetCurrentVersion(name, sectname);
+
+    (* Wenn die Version im Repo aelter oder gleich alt wie unsere ist, brauchen
+       wir nichts zu tun. *)
+    if (ver = nil) or (ver.compareTo(verRepo) >= 0) then begin
+        WriteLn(rsNoUpdatesAvailable);
+        Exit;
+    end;
+
+    RemoveVersion(ver);
+    Get(name, false);
+end;
+
+(**
  * Alle installierten Pakete aktualisieren
  *)
 procedure UpgradeAll;
@@ -632,6 +682,13 @@ begin
             WriteLn(rsWrongParamCount);
             PrintUsage;
         end;
+    end else if system.ParamStr(1) = 'upgrade' then begin
+        if system.ParamCount = 2 then begin
+            Upgrade(system.ParamStr(2));
+        end else begin
+            WriteLn(rsWrongParamCount);
+            PrintUsage;
+        end;
     end else if system.ParamStr(1) = 'upgrade-all' then begin
         if system.ParamCount = 1 then begin
             UpgradeAll;
-- 
1.6.3.3