]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
Fold build(Install|Source)(MD5|SHA512) into buildPackage(Install|Source)
authorJon Turney <jon.turney@dronecode.org.uk>
Fri, 28 Apr 2017 21:11:47 +0000 (22:11 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Tue, 23 May 2017 16:17:21 +0000 (17:17 +0100)
Fold build(Install|Source)(MD5|SHA512) into buildPackage(Install|Source), so
the (pathname, size, hash) information from an install: or source: line is
all processed together.

IniDBBuilderPackage.cc
IniDBBuilderPackage.h
iniparse.yy

index c90bfe35ebf0fc963e6a650f28d2ac3e7b6028d8..ad1cc8879a728748c205b748876aa5d34acf65fc 100644 (file)
@@ -120,15 +120,37 @@ IniDBBuilderPackage::buildPackageLDesc (const std::string& theDesc)
 
 void
 IniDBBuilderPackage::buildPackageInstall (const std::string& path,
-                                          const std::string& size)
+                                          const std::string& size,
+                                          char *hash,
+                                          hashType type)
 {
   process_src (*cbpv.source(), path);
   setSourceSize (*cbpv.source(), size);
+
+  switch (type) {
+  case hashType::sha512:
+    if (hash && !cbpv.source()->sha512_isSet)
+      {
+        memcpy (cbpv.source()->sha512sum, hash, sizeof(cbpv.source()->sha512sum));
+        cbpv.source()->sha512_isSet = true;
+      }
+    break;
+
+  case hashType::md5:
+    if (hash && !cbpv.source()->md5.isSet())
+      cbpv.source()->md5.set((unsigned char *)hash);
+    break;
+
+  case hashType::none:
+    break;
+  }
 }
 
 void
 IniDBBuilderPackage::buildPackageSource (const std::string& path,
-                                         const std::string& size)
+                                         const std::string& size,
+                                         char *hash,
+                                         hashType type)
 {
   packagedb db;
   /* get an appropriate metadata */
@@ -168,6 +190,24 @@ IniDBBuilderPackage::buildPackageSource (const std::string& path,
   spec.setVersion (cbpv.Canonical_version());
 
   setSourceSize (*cspv.source(), size);
+
+  switch (type) {
+  case hashType::sha512:
+    if (hash && !cspv.source()->sha512_isSet)
+      {
+        memcpy (cspv.source()->sha512sum, hash, sizeof(cspv.source()->sha512sum));
+        cspv.source()->sha512_isSet = true;
+      }
+    break;
+
+  case hashType::md5:
+    if (hash && !cspv.source()->md5.isSet())
+      cspv.source()->md5.set((unsigned char *)hash);
+    break;
+
+  case hashType::none:
+    break;
+  }
 }
 
 void
@@ -199,38 +239,6 @@ IniDBBuilderPackage::buildBeginDepends ()
   currentNodeList = cbpv.depends();
 }
 
-void
-IniDBBuilderPackage::buildInstallSHA512 (unsigned char const *sha512)
-{
-  if (sha512 && !cbpv.source()->sha512_isSet) {
-    memcpy (cbpv.source()->sha512sum, sha512, sizeof cbpv.source()->sha512sum);
-    cbpv.source()->sha512_isSet = true;
-  }
-}
-
-void
-IniDBBuilderPackage::buildSourceSHA512 (unsigned char const *sha512)
-{
-  if (sha512 && !cspv.source()->sha512_isSet) {
-    memcpy (cspv.source()->sha512sum, sha512, sizeof cspv.source()->sha512sum);
-    cspv.source()->sha512_isSet = true;
-  }
-}
-
-void
-IniDBBuilderPackage::buildInstallMD5 (unsigned char const *md5)
-{
-  if (md5 && !cbpv.source()->md5.isSet())
-    cbpv.source()->md5.set(md5);
-}
-
-void
-IniDBBuilderPackage::buildSourceMD5 (unsigned char const *md5)
-{
-  if (md5 && !cspv.source()->md5.isSet())
-    cspv.source()->md5.set(md5);
-}
-
 void
 IniDBBuilderPackage::buildBeginBuildDepends ()
 {
index 1dab41bc6d877b7ca543b57e2f8514fa2284ff8e..766a5efcf49c07700e66e5e36aa9a8d75c78acbb 100644 (file)
 
 #include <vector>
 #include "package_version.h"
+
 class IniParseFeedback;
 class packagesource;
 class packagemeta;
 
+enum class hashType { none, md5, sha512 };
+
 class IniDBBuilderPackage
 {
 public:
@@ -34,16 +37,21 @@ public:
   void buildPackageVersion (const std::string& );
   void buildPackageSDesc (const std::string& );
   void buildPackageLDesc (const std::string& );
-  void buildPackageInstall (const std::string&, const std::string&);
-  void buildPackageSource (const std::string&, const std::string&);
+  void buildPackageInstall (const std::string&, const std::string&,
+                            char *, hashType);
+  void buildPackageSource (const std::string&, const std::string&,
+                           char *, hashType);
+
+  // helpers for ScanFindVisitor
+  void buildPackageInstall (const std::string& path, const std::string& size)
+  { buildPackageInstall(path, size, NULL, hashType::none); }
+  void buildPackageSource (const std::string& path, const std::string& size)
+  { buildPackageSource(path, size, NULL, hashType::none); }
+
   void buildPackageTrust (int);
   void buildPackageCategory (const std::string& );
 
   void buildBeginDepends ();
-  void buildInstallSHA512 (unsigned char const[64]);
-  void buildSourceSHA512 (unsigned char const[64]);
-  void buildInstallMD5 (unsigned char const[16]);
-  void buildSourceMD5 (unsigned char const[16]);
   void buildBeginBuildDepends ();
   void buildMessage (const std::string&, const std::string&);
   void buildSourceName (const std::string& );
index 98b51bb409b45a42723bc12241d8ea5dc3b19829..d768400421b60427e0726f65c035614811227b9b 100644 (file)
@@ -96,8 +96,10 @@ singleitem /* non-empty */
  | T_OTHER NL                  { iniBuilder->buildPackageTrust (TRUST_OTHER); }
  | SOURCEPACKAGE source NL
  | CATEGORY categories NL
- | INSTALL STRING STRING { iniBuilder->buildPackageInstall ($2, $3);} installchksum NL
- | SOURCE STRING STRING sourcechksum NL {iniBuilder->buildPackageSource ($2, $3);}
+ | INSTALL STRING STRING MD5 NL { iniBuilder->buildPackageInstall ($2, $3, $4, hashType::md5); }
+ | INSTALL STRING STRING SHA512 NL { iniBuilder->buildPackageInstall ($2, $3, $4, hashType::sha512); }
+ | SOURCE STRING STRING MD5 NL {iniBuilder->buildPackageSource ($2, $3, $4, hashType::md5); }
+ | SOURCE STRING STRING SHA512 NL {iniBuilder->buildPackageSource ($2, $3, $4, hashType::sha512); }
  | DEPENDS { iniBuilder->buildBeginDepends(); } versionedpackagelist NL
  | REQUIRES { iniBuilder->buildBeginDepends(); } versionedpackagelistsp NL
  | BUILDDEPENDS { iniBuilder->buildBeginBuildDepends(); } versionedpackagelist NL
@@ -112,16 +114,6 @@ categories: /* empty */
  | categories STRING           { iniBuilder->buildPackageCategory ($2); }
  ;
 
-installchksum /* non-empty */
- : MD5                         { iniBuilder->buildInstallMD5 ((unsigned char *)$1);}
- | SHA512              { iniBuilder->buildInstallSHA512 ((unsigned char *)$1);}
- ;
-
-sourcechksum /* non-empty */
- : MD5                         { iniBuilder->buildSourceMD5 ((unsigned char *)$1); }
- | SHA512              { iniBuilder->buildSourceSHA512 ((unsigned char *)$1); }
- ;
-
 source /* non-empty */
  : STRING { iniBuilder->buildSourceName ($1); } versioninfo
  ;
This page took 0.062086 seconds and 5 git commands to generate.