This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup 07/15] Simplify class packagesource


packagesource::Filename() is unused

packagesource::Base() was only used in reporting progress in install.
Instead report the package name and package version.  (It would be nice to
do so consistently in uninstall well, but we don't really know what version
we are uninstalling)

The default copy constructor is not overriden, which is unsafe, as the class
contains a pointer to new-ed memory. Use std::string instead, retaining the
relied-upon behaviour of returning NULL for an empty string.
---
 install.cc        | 24 ++++++++++++------------
 package_source.cc | 48 ++++--------------------------------------------
 package_source.h  | 39 ++++++++-------------------------------
 3 files changed, 24 insertions(+), 87 deletions(-)

diff --git a/install.cc b/install.cc
index fb3e93f..6e59a80 100644
--- a/install.cc
+++ b/install.cc
@@ -148,7 +148,7 @@ Installer::StandardDirs[] = {
 };
 
 static int num_installs, num_uninstalls;
-static void chksum_one (const packagesource& source);
+static void chksum_one (const packagemeta &pkg, const packagesource& pkgsource);
 
 void
 Installer::preremoveOne (packagemeta & pkg)
@@ -362,7 +362,7 @@ Installer::installOne (packagemeta &pkgm, const packageversion &ver,
   if (!source.Canonical())
     return;
   Progress.SetText1 ("Installing");
-  Progress.SetText2 (source.Base () ? source.Base () : "(unknown)");
+  Progress.SetText2 ((pkgm.name + "-" + ver.Canonical_version()).c_str());
 
   io_stream *pkgfile = NULL;
 
@@ -763,7 +763,7 @@ do_install_thread (HINSTANCE h, HWND owner)
     {
       try
       {
-        chksum_one (*pkg.desired.source ());
+        chksum_one (pkg, *pkg.desired.source ());
       }
       catch (Exception *e)
       {
@@ -783,7 +783,7 @@ do_install_thread (HINSTANCE h, HWND owner)
       bool skiprequested = false ;
       try
       {
-        chksum_one (*pkg.desired.sourcePackage ().source ());
+        chksum_one (pkg, *pkg.desired.sourcePackage ().source ());
       }
       catch (Exception *e)
       {
@@ -930,7 +930,7 @@ sha512_str (const unsigned char *in, char *buf)
 }
 
 static void
-sha512_one (const packagesource& pkgsource)
+sha512_one (const packagemeta &pkg, const packagesource& pkgsource)
 {
   std::string fullname (pkgsource.Cached ());
 
@@ -949,7 +949,7 @@ sha512_one (const packagesource& pkgsource)
   Log (LOG_BABBLE) << "Checking SHA512 for " << fullname << endLog;
 
   Progress.SetText1 ((std::string ("Checking SHA512 for ")
-		      + pkgsource.Base ()).c_str ());
+		      + pkg.name).c_str ());
   Progress.SetText4 ("Progress:");
   Progress.SetBar1 (0);
 
@@ -986,7 +986,7 @@ sha512_one (const packagesource& pkgsource)
 }
 
 static void
-md5_one (const packagesource& pkgsource)
+md5_one (const packagemeta &pkg, const packagesource& pkgsource)
 {
   std::string fullname (pkgsource.Cached ());
 
@@ -1001,7 +1001,7 @@ md5_one (const packagesource& pkgsource)
   Log (LOG_BABBLE) << "Checking MD5 for " << fullname << endLog;
 
   Progress.SetText1 ((std::string ("Checking MD5 for ")
-		      + pkgsource.Base ()).c_str ());
+		      + pkg.name).c_str ());
   Progress.SetText4 ("Progress:");
   Progress.SetBar1 (0);
 
@@ -1035,16 +1035,16 @@ md5_one (const packagesource& pkgsource)
 }
 
 static void
-chksum_one (const packagesource& pkgsource)
+chksum_one (const packagemeta &pkg, const packagesource& pkgsource)
 {
   if (!pkgsource.Cached ())
     return;
   if (pkgsource.sha512_isSet)
-    sha512_one (pkgsource);
+    sha512_one (pkg, pkgsource);
   else if (pkgsource.md5.isSet())
-    md5_one (pkgsource);
+    md5_one (pkg, pkgsource);
   else
-    Log (LOG_BABBLE) << "No checksum recorded for " << pkgsource.Base ()
+    Log (LOG_BABBLE) << "No checksum recorded for " << pkg.name
 		     << ", cannot determine integrity of package!"
 		     << endLog;
 }
diff --git a/package_source.cc b/package_source.cc
index 192fe5f..15540f6 100644
--- a/package_source.cc
+++ b/package_source.cc
@@ -14,59 +14,19 @@
  */
 
 /* this is the parent class for all package source (not source code - installation
- * source as in http/ftp/disk file) operations. 
+ * source as in http/ftp/disk file) operations.
  */
 
-#include <stdlib.h>
-#include <strings.h>
 #include "package_source.h"
 
 site::site (const std::string& newkey) : key(newkey)
 {
-};
-  
+}
+
 void
 packagesource::set_canonical (char const *fn)
 {
-  if (canonical)
-    delete[] canonical;
-  canonical = new char[strlen (fn) + 1];
-  strcpy (canonical, fn);
-
-  /* The base is from the last '/' to the '.tar' following the last - */
-  char const *bstart = strchr (fn, '/');
-  char const *tmp;
-  while (bstart && (tmp = strchr (bstart + 1, '/')))
-    bstart = tmp;
-
-  if (bstart)
-    bstart++;
-  else
-    bstart = fn;
-  char const *bend = strchr (bstart, '-');
-  while (bend && (tmp = strchr (bend + 1, '-')))
-    bend = tmp;
-  if (bend)
-    bend = strstr (bend, ".tar");
-  else
-    bend = strstr (bstart, ".tar");
-
-  if (!bend)
-    bend = strchr (bstart, '\0');
-  char const *end = strchr (fn, '\0');
-  if (base)
-    delete[] base;
-  base = new char[bend - bstart + 1];
-  memcpy (base, bstart, bend - bstart);
-  base[bend - bstart] = '\0';
-
-  if (filename)
-    delete[] filename;
-  filename = new char[end - bstart + 1];
-  memcpy (filename, bstart, end - bstart);
-  filename[end - bstart] = '\0';
-
-  cached = std::string();
+  canonical = fn;
 }
 
 void
diff --git a/package_source.h b/package_source.h
index 883ff08..8675c51 100644
--- a/package_source.h
+++ b/package_source.h
@@ -41,33 +41,22 @@ public:
 class packagesource
 {
 public:
-  packagesource ():size (0), canonical (0), base (0), filename (0), cached ()
+  packagesource ():size (0), canonical (), cached ()
   {
     memset (sha512sum, 0, sizeof sha512sum);
     sha512_isSet = false;
   };
   /* how big is the source file */
   size_t size;
-  /* The canonical name - the complete path to the source file 
+  /* The canonical name - the complete path to the source file
    * i.e. foo/bar/package-1.tar.bz2
    */
   const char *Canonical () const
   {
-    return canonical;
-  };
-  /* The basename - without extention 
-   * i.e. package-1
-   */
-  const char *Base () const
-  {
-    return base;
-  };
-  /* The basename - with extention 
-   * i.e. package-1.tar.bz2
-   */
-  const char *Filename () const
-  {
-    return filename;
+    if (!canonical.empty())
+      return canonical.c_str();
+
+    return NULL;
   };
   /* what is the cached filename, to prevent directory scanning during install */
   char const *Cached () const
@@ -77,7 +66,7 @@ public:
       return NULL;
     return cached.c_str();
   };
-  /* sets the canonical path, and parses and creates base and filename */
+  /* sets the canonical path */
   void set_canonical (char const *);
   void set_cached (const std::string& );
   unsigned char sha512sum[SHA512_DIGEST_LENGTH];
@@ -86,20 +75,8 @@ public:
   typedef std::vector <site> sitestype;
   sitestype sites;
 
-  ~packagesource ()
-  {
-    if (canonical)
-      delete []canonical;
-    if (base)
-      delete []base;
-    if (filename)
-      delete []filename;
-  };
-
 private:
-  char *canonical;
-  char *base;
-  char *filename;
+  std::string canonical;
   std::string cached;
 };
 
-- 
2.12.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]