OSDN Git Service

Add CLI support for "update" action.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 17 Dec 2009 17:35:12 +0000 (17:35 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 17 Dec 2009 17:35:12 +0000 (17:35 +0000)
ChangeLog
src/climain.cpp
src/pkgbase.h
src/pkgbind.cpp
src/pkgexec.cpp
src/pkgtask.h

index 7142ac9..c7c372c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2009-12-17  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Add CLI support for "update" action.
+
+       * src/pkgtask.h (ACTION_UPDATE): Define it, derived from...
+       (action_update): ...this new entry in anonymous enumeration.
+       
+       * src/pkgexec.cpp (action_name): Add "update" keyword identification.
+
+       * src/pkgbase.h: Typo in comment; s/xwXmlDocument/wxXmlDocument/.
+       (pkgXmlDocument::BindRepositories): Add `force_update' parameter...
+       * src/pkgbind.cpp (pkgXmlDocument::BindRepositories): Use it to...
+       (pkgXmlDocument::SyncRepository): ...invoke this method when passed as
+       a `true' flag, in addition to (as previously) first time reference.
+
+       * src/climain.cpp (climain): Interpret "update" keyword for...
+       [ACTION_UPDATE]: ...passing state as `force_update' parameter to...
+       (pkgXmlDocument::BindRepositories): ...this method, then...
+       [!ACTION_UPDATE]: Follow with normal action processing.
+
 2009-12-16  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Add status checking for Internet URL connections.
index 9738e88..5d1645a 100644 (file)
@@ -75,23 +75,30 @@ EXTERN_C int climain( int argc, char **argv )
     /* Merge all package lists, as specified in the "repository"
      * section of the "profile", into the XML database tree...
      */
-    if( dbase.BindRepositories() == NULL )
+    if( dbase.BindRepositories( action == ACTION_UPDATE ) == NULL )
       /*
        * ...bailing out, on an invalid profile specification...
        */
       dmh_notify( DMH_FATAL, "%s: invalid application profile\n", dbase.Value() );
 
 #if 0
-    /* Now schedule the specified action for each additionally
-     * specified command line argument, (each of which is assumed
-     * to represent a package name...
+    /* If the requested action was "update", then we've already done it,
+     * as a side effect of binding the cached repository catalogues...
      */
-    while( --argc )
-      dbase.Schedule( (unsigned long)(action), *++argv );
+    if( action != ACTION_UPDATE )
+    {
+      /* ...otherwise, we still need to schedule and execute the action request...
+       *
+       * so, schedule the specified action for each additionally specified command
+       * line argument, (each of which is assumed to represent a package name)...
+       */
+      while( --argc )
+       dbase.Schedule( (unsigned long)(action), *++argv );
 
-    /* ...and finally, execute all scheduled actions...
-     */
-    dbase.ExecuteActions();
+      /* ...and finally, execute all scheduled actions...
+       */
+      dbase.ExecuteActions();
+    }
 #endif
 
     /* If we get this far, then all actions completed successfully;
index 5c70d31..92fd531 100644 (file)
@@ -193,7 +193,7 @@ class pkgXmlDocument : public TiXmlDocument
      */
     inline pkgXmlDocument( const char* name )
     {
-      /* tinyxml has a similar constructor, but unlike xwXmlDocument,
+      /* tinyxml has a similar constructor, but unlike wxXmlDocument,
        * it DOES NOT automatically load the document; force it.
        */
       LoadFile( name );
@@ -235,7 +235,7 @@ class pkgXmlDocument : public TiXmlDocument
     /* Method to merge content from repository-specific package lists
      * into the central XML package database.
      */
-    pkgXmlNode* BindRepositories();
+    pkgXmlNode* BindRepositories( bool );
 
     /* Method to locate the XML database entry for a named package.
      */
index b2431fc..56493d8 100644 (file)
@@ -32,7 +32,7 @@
 #include "dmh.h"
 #include "pkgbase.h"
 
-pkgXmlNode *pkgXmlDocument::BindRepositories()
+pkgXmlNode *pkgXmlDocument::BindRepositories( bool force_update )
 {
   /* Identify the repositories specified in the application profile,
    * and merge their associated package distribution lists into the
@@ -71,9 +71,9 @@ pkgXmlNode *pkgXmlDocument::BindRepositories()
        {
          /* Check for a locally cached copy of the "package-list" file...
           */
-         if( access( dfile, F_OK ) != 0 )
+         if( force_update || (access( dfile, F_OK ) != 0) )
            /*
-            * When no local copy is available...
+            * When performing an "update", or if no local copy is available...
             * Force a "sync", to fetch a copy from the public host.
             */
            SyncRepository( dname, repository );
index 62a3d0b..074de80 100644 (file)
@@ -42,7 +42,9 @@ EXTERN_C const char *action_name( unsigned long index )
     "no change",       /* unused; zero cannot test true in a bitwise test  */
     "remove",          /* remove a previously installed package            */
     "install",         /* install a new package                            */
-    "upgrade"          /* update previously installed packages             */
+    "upgrade",         /* upgrade previously installed packages            */
+
+    "update"           /* update local copy of repository catalogues       */
   };
 
   /* For specified "index", return a pointer to the associated keyword,
index 72f205a..624cbbd 100644 (file)
 enum
 {
   action_none = 0,
+
   action_remove,
   action_install,
   action_upgrade,
 
+  action_update,
+
   end_of_actions
 };
 
@@ -44,6 +47,7 @@ enum
 #define ACTION_REMOVE   (unsigned long)(action_remove)
 #define ACTION_INSTALL  (unsigned long)(action_install)
 #define ACTION_UPGRADE  (unsigned long)(action_upgrade)
+#define ACTION_UPDATE   (unsigned long)(action_update)
 
 #define STRICTLY_GT    ACTION_MASK + 1
 #define STRICTLY_LT    STRICTLY_GT << 1