public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 07/15] Simplify class packagesource
Date: Tue, 16 May 2017 11:50:00 -0000	[thread overview]
Message-ID: <20170516114900.168120-8-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20170516114900.168120-1-jon.turney@dronecode.org.uk>

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

  parent reply	other threads:[~2017-05-16 11:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16 11:49 [PATCH setup 00/15] Various setup patches Jon Turney
2017-05-16 11:49 ` [PATCH setup 01/15] Add Makefile rule to rename build products to form used when uploading Jon Turney
2017-05-16 11:49 ` [PATCH setup 06/15] Remove unneeded virtual from class packagesource's methods Jon Turney
2017-05-16 11:49 ` [PATCH setup 05/15] Remove unused forward declaration of non-existent class category Jon Turney
2017-05-16 11:49 ` [PATCH setup 03/15] Rename "Internet Explorer Proxy Settings" to "System Proxy Settings" Jon Turney
2017-05-16 11:49 ` [PATCH setup 02/15] Don't bother storing prev version Jon Turney
2017-05-16 11:49 ` [PATCH setup 04/15] Remove packageversion::sources(), only packageversion::source() is useful Jon Turney
2017-05-16 11:50 ` Jon Turney [this message]
2017-05-16 11:51 ` [PATCH setup 09/15] Initial setting of trust should be TRUST_CURR Jon Turney
2017-05-16 11:51 ` [PATCH setup 08/15] Fix comments and indentation in check_for_cached Jon Turney
2017-05-23 17:34   ` Achim Gratz
2017-05-16 11:58 ` [PATCH setup 10/15] Change PackageSpecification::_operator to an enum Jon Turney
2017-05-16 11:58   ` [PATCH setup 12/15] Stop pretending to support complex dependencies Jon Turney
2017-05-16 11:58   ` [PATCH setup 11/15] Remove useless PackageSpecification methods Jon Turney
2017-05-16 11:59   ` [PATCH setup 13/15] All, rather than just the first (usually current) version should get dependencies Jon Turney
2017-05-16 12:00   ` [PATCH setup 14/15] Make PackageDepends a type Jon Turney
2017-05-16 12:04   ` [PATCH setup 15/15] Add some progress reporting during preremove and uninstall Jon Turney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170516114900.168120-8-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).