From cb6a2b3eaca4353d7f490fb360b98c08d64a2d8c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 14 Jan 2013 07:09:51 +0100 Subject: first iteration that adds support for checksums-{sha512,sha256} --- apt-pkg/deb/debsrcrecords.cc | 129 +++++++++++++++++++++++++------------------ apt-pkg/srcrecords.h | 2 +- 2 files changed, 76 insertions(+), 55 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index ce55ccd1f..45cc0ae82 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -17,6 +17,7 @@ #include #include #include +#include using std::max; /*}}}*/ @@ -114,64 +115,84 @@ bool debSrcRecordParser::BuildDepends(std::vector &List) { List.erase(List.begin(),List.end()); + + const char *hash_field[] = { "Checksums-Sha512", + "Checksums-Sha256", + "Checksums-Sha1", + "Files", // historic name + NULL, + }; + const char *hash_type[] = { "Sha512", + "Sha256", + "Sha1", + "md5sum", + NULL, + }; - string Files = Sect.FindS("Files"); - if (Files.empty() == true) - return false; - - // Stash the / terminated directory prefix - string Base = Sect.FindS("Directory"); - if (Base.empty() == false && Base[Base.length()-1] != '/') - Base += '/'; - - std::vector const compExts = APT::Configuration::getCompressorExtensions(); - - // Iterate over the entire list grabbing each triplet - const char *C = Files.c_str(); - while (*C != 0) - { - pkgSrcRecords::File F; - string Size; - - // Parse each of the elements - if (ParseQuoteWord(C,F.MD5Hash) == false || - ParseQuoteWord(C,Size) == false || - ParseQuoteWord(C,F.Path) == false) - return _error->Error("Error parsing file record"); - - // Parse the size and append the directory - F.Size = atoi(Size.c_str()); - F.Path = Base + F.Path; - - // Try to guess what sort of file it is we are getting. - string::size_type Pos = F.Path.length()-1; - while (1) - { - string::size_type Tmp = F.Path.rfind('.',Pos); - if (Tmp == string::npos) - break; - if (F.Type == "tar") { - // source v3 has extension 'debian.tar.*' instead of 'diff.*' - if (string(F.Path, Tmp+1, Pos-Tmp) == "debian") - F.Type = "diff"; - break; - } - F.Type = string(F.Path,Tmp+1,Pos-Tmp); - - if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() || - F.Type == "tar") - { - Pos = Tmp-1; - continue; - } + for (int i=0; hash_field[i] != NULL; i++) + { + + string Files = Sect.FindS(hash_field[i]); + if (Files.empty() == true) + continue; + + // Stash the / terminated directory prefix + string Base = Sect.FindS("Directory"); + if (Base.empty() == false && Base[Base.length()-1] != '/') + Base += '/'; + + std::vector const compExts = APT::Configuration::getCompressorExtensions(); + + // Iterate over the entire list grabbing each triplet + const char *C = Files.c_str(); + while (*C != 0) + { + pkgSrcRecords::File F; + string Size; + + // Parse each of the elements + std::string RawHash; + if (ParseQuoteWord(C, RawHash) == false || + ParseQuoteWord(C, Size) == false || + ParseQuoteWord(C, F.Path) == false) + return _error->Error("Error parsing '%s' record", hash_field[i]); + // assign full hash string + F.Hash = HashString(hash_type[i], RawHash).toStr(); + + // Parse the size and append the directory + F.Size = atoi(Size.c_str()); + F.Path = Base + F.Path; + + // Try to guess what sort of file it is we are getting. + string::size_type Pos = F.Path.length()-1; + while (1) + { + string::size_type Tmp = F.Path.rfind('.',Pos); + if (Tmp == string::npos) + break; + if (F.Type == "tar") { + // source v3 has extension 'debian.tar.*' instead of 'diff.*' + if (string(F.Path, Tmp+1, Pos-Tmp) == "debian") + F.Type = "diff"; + break; + } + F.Type = string(F.Path,Tmp+1,Pos-Tmp); + + if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() || + F.Type == "tar") + { + Pos = Tmp-1; + continue; + } - break; - } + break; + } - List.push_back(F); + List.push_back(F); + } + break; } - - return true; + return (List.size() > 0); } /*}}}*/ // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/ diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h index ed69d0d72..7cb490079 100644 --- a/apt-pkg/srcrecords.h +++ b/apt-pkg/srcrecords.h @@ -31,7 +31,7 @@ class pkgSrcRecords // Describes a single file struct File { - std::string MD5Hash; + std::string Hash; unsigned long Size; std::string Path; std::string Type; -- cgit v1.2.3 From 64680d3bf12db6599e93f950546e380e0bd5ddf4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 14 Jan 2013 07:59:52 +0100 Subject: fix skipping of already downloaded files and add some FIXMEs --- apt-pkg/deb/debsrcrecords.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 45cc0ae82..c620c2298 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -116,16 +116,21 @@ bool debSrcRecordParser::Files(std::vector &List) { List.erase(List.begin(),List.end()); + // FIXME: build string dynamically from + // Hashes::SupportedHashes const char *hash_field[] = { "Checksums-Sha512", "Checksums-Sha256", "Checksums-Sha1", "Files", // historic name NULL, }; - const char *hash_type[] = { "Sha512", - "Sha256", - "Sha1", - "md5sum", + + // FIXME: use string from Hashes::SupportedHashes + // FIXME2: this is case senstivie + const char *hash_type[] = { "SHA512", + "SHA256", + "SHA1", + "MD5Sum", NULL, }; -- cgit v1.2.3 From 3bbce699ee1a5dbbe37806aee7afcc615ecc6ebe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Jan 2013 06:59:24 +0100 Subject: cleanup the hash iteration. unfortunately there is no 1:1 mapping from Hashes::SupporedHashes to the tag name --- apt-pkg/deb/debsrcrecords.cc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index c620c2298..37d38ee5b 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -116,28 +116,21 @@ bool debSrcRecordParser::Files(std::vector &List) { List.erase(List.begin(),List.end()); - // FIXME: build string dynamically from - // Hashes::SupportedHashes - const char *hash_field[] = { "Checksums-Sha512", - "Checksums-Sha256", - "Checksums-Sha1", - "Files", // historic name - NULL, - }; - - // FIXME: use string from Hashes::SupportedHashes - // FIXME2: this is case senstivie - const char *hash_type[] = { "SHA512", - "SHA256", - "SHA1", - "MD5Sum", - NULL, + // map from the Hashsum field to the hashsum function, + // unfortunately this is not a 1:1 mapping from + // Hashes::SupporedHashes as e.g. Files is a historic name for the md5 + const std::pair SourceHashFields[] = { + std::make_pair( "Checksums-Sha512", "SHA512"), + std::make_pair( "Checksums-Sha256", "SHA256"), + std::make_pair( "Checksums-Sha1", "SHA1"), + std::make_pair( "Files", "MD5Sum"), // historic Name }; - for (int i=0; hash_field[i] != NULL; i++) + for (unsigned int i=0; + i < sizeof(SourceHashFields)/sizeof(SourceHashFields[0]); + i++) { - - string Files = Sect.FindS(hash_field[i]); + string Files = Sect.FindS(SourceHashFields[i].first); if (Files.empty() == true) continue; @@ -160,9 +153,10 @@ bool debSrcRecordParser::Files(std::vector &List) if (ParseQuoteWord(C, RawHash) == false || ParseQuoteWord(C, Size) == false || ParseQuoteWord(C, F.Path) == false) - return _error->Error("Error parsing '%s' record", hash_field[i]); + return _error->Error("Error parsing '%s' record", + SourceHashFields[i].first); // assign full hash string - F.Hash = HashString(hash_type[i], RawHash).toStr(); + F.Hash = HashString(SourceHashFields[i].second, RawHash).toStr(); // Parse the size and append the directory F.Size = atoi(Size.c_str()); -- cgit v1.2.3 From a1b5561a036ebbe416cccfb2bd476a838ddb6286 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Feb 2013 18:28:44 +0100 Subject: re-add compat pkgSrcRecords::File::MD5Hash --- apt-pkg/deb/debsrcrecords.cc | 3 +++ apt-pkg/srcrecords.h | 1 + 2 files changed, 4 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 37d38ee5b..f5fb2da4a 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -157,6 +157,9 @@ bool debSrcRecordParser::Files(std::vector &List) SourceHashFields[i].first); // assign full hash string F.Hash = HashString(SourceHashFields[i].second, RawHash).toStr(); + // API compat hack + if(SourceHashFields[i].second == "MD5Sum") + F.MD5Hash = RawHash; // Parse the size and append the directory F.Size = atoi(Size.c_str()); diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h index 7cb490079..796d2e1bd 100644 --- a/apt-pkg/srcrecords.h +++ b/apt-pkg/srcrecords.h @@ -31,6 +31,7 @@ class pkgSrcRecords // Describes a single file struct File { + std::string MD5Hash; std::string Hash; unsigned long Size; std::string Path; -- cgit v1.2.3 From 36e42433c3a1f04b7c3417b313418fd1c6b035fe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 1 Mar 2013 12:27:07 +0100 Subject: add changelog and make it a real abi break --- apt-pkg/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/init.h b/apt-pkg/init.h index b6f3df753..00d361560 100644 --- a/apt-pkg/init.h +++ b/apt-pkg/init.h @@ -27,7 +27,7 @@ class Configuration; // Non-ABI-Breaks should only increase RELEASE number. // See also buildlib/libversion.mak #define APT_PKG_MAJOR 4 -#define APT_PKG_MINOR 12 +#define APT_PKG_MINOR 13 #define APT_PKG_RELEASE 0 extern const char *pkgVersion; -- cgit v1.2.3