diff options
author | Ishan Jayawardena <udeshike@gmail.com> | 2011-06-05 18:48:42 +0530 |
---|---|---|
committer | Ishan Jayawardena <udeshike@gmail.com> | 2011-06-05 18:48:42 +0530 |
commit | b8b21ea0d77e70b08948a594c6741252a39a6ca2 (patch) | |
tree | 9e9d666f7764fd4cf59789e2a51e4db8a88750f7 | |
parent | bdda60d6fb5a915380398b40b0c4777c4e51850d (diff) |
added a script to test the debdelta method.
-rw-r--r-- | methods/debdelta.cc | 84 | ||||
-rwxr-xr-x | test/methods/debdelta/test-signature | 47 | ||||
-rw-r--r-- | test/methods/debdelta/test.txt | 1 |
3 files changed, 103 insertions, 29 deletions
diff --git a/methods/debdelta.cc b/methods/debdelta.cc index 96a1d7f80..d908e2a51 100644 --- a/methods/debdelta.cc +++ b/methods/debdelta.cc @@ -1,10 +1,12 @@ // Includes /*{{{*/ +#include <apt-pkg/acquire-item.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/mmap.h> #include <apt-pkg/error.h> #include <apt-pkg/acquire-method.h> #include <apt-pkg/strutl.h> #include <apt-pkg/hashes.h> +#include <apt-pkg/init.h> #include <sys/stat.h> #include <sys/uio.h> @@ -16,7 +18,8 @@ #include <apti18n.h> /*}}}*/ -/** \brief DebdeltaMethod - TODO: say something about debdelta here! +/** \brief DebdeltaMethod - This method is used to patch a new deb from + * an input deb and a debdelta file. * */ class DebdeltaMethod : public pkgAcqMethod { bool Debug; @@ -31,15 +34,21 @@ public: bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/ { - std::cerr << "Starting DebdeltaMethod::Fetch()." << std::endl; - Debug = false;//_config->FindB("Debug::pkgAcquire::RRed", false); - string oldDebFile = Itm->DestFile; - string debDeltaFile = Itm->Uri; + Debug = _config->FindB("Debug::pkgAcquire::RRed", false); + string OldDebFile = Itm->DestFile; + string DebDeltaFile = Itm->Uri; - if (debDeltaFile.empty()) + if (!FileExists(OldDebFile)) + OldDebFile = "/"; + + if (!FileExists(DebDeltaFile)) return _error->Error("Could not find a debdelta file."); - Itm->DestFile = GetNewPackageName(debDeltaFile); + string NewDeb = GetNewPackageName(DebDeltaFile); + Itm->DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + NewDeb; + if (FileExists(Itm->DestFile)) + return _error->Error("New .deb already exists."); + pid_t Process = ExecFork(); if (Process == 0) { @@ -48,11 +57,8 @@ bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/ if (!FileExists(Args[0])) return _error->Error("Could not find debpatch."); Args[1] = "-A"; - Args[2] = debDeltaFile.c_str(); - if (oldDebFile.empty()) - Args[3] = "/"; - else - Args[3] = oldDebFile.c_str(); + Args[2] = DebDeltaFile.c_str(); + Args[3] = OldDebFile.c_str(); Args[4] = Itm->DestFile.c_str(); if (Debug == true) { @@ -62,7 +68,18 @@ bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/ } execv(Args[0], (char **)Args); } - return ExecWait(Process, "debpatch"); + if (ExecWait(Process, "debpatch")) + { + if (!FileExists(Itm->DestFile)) + return _error->Error("Failed to patch %s", Itm->DestFile.c_str()); + // move the .deb to Dir::Cache::Archives + OldDebFile = _config->FindDir("Dir::Cache::Archives") + NewDeb; + Rename(Itm->DestFile, OldDebFile); + Itm->DestFile = OldDebFile; + return true; + } + Itm->DestFile = OldDebFile; + return false; } /** @@ -71,19 +88,18 @@ bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/ * @param debdeltaName the name of the debdelta file. * @return path/P_N_A.deb */ -string DebdeltaMethod::GetNewPackageName(string debdeltaName) +string DebdeltaMethod::GetNewPackageName(string DebdeltaName) { - int slashpos = debdeltaName.rfind("/", debdeltaName.length() - 1); - string path = debdeltaName.substr(0, slashpos + 1); - debdeltaName = debdeltaName.substr(slashpos + 1, debdeltaName.length() - 1); - int newBegin = debdeltaName.find("_", 0); - string pckgName = debdeltaName.substr(0, newBegin); - newBegin = debdeltaName.find("_", newBegin + 1); - int newEnd = debdeltaName.find("_", newBegin + 1); - string newVersion = debdeltaName.substr(newBegin + 1, newEnd - newBegin - 1); - string arch = debdeltaName.substr(newEnd + 1, debdeltaName.find(".", newEnd + 1) - newEnd - 1); - string debname = pckgName + "_" + newVersion + "_" + arch + ".deb"; - return path+debname; + int Slashpos = DebdeltaName.rfind("/", DebdeltaName.length() - 1); + string Path = DebdeltaName.substr(0, Slashpos + 1); + DebdeltaName = DebdeltaName.substr(Slashpos + 1, DebdeltaName.length() - 1); + int NewBegin = DebdeltaName.find("_", 0); + string PkgName = DebdeltaName.substr(0, NewBegin); + NewBegin = DebdeltaName.find("_", NewBegin + 1); + int NewEnd = DebdeltaName.find("_", NewBegin + 1); + string NewVersion = DebdeltaName.substr(NewBegin + 1, NewEnd - NewBegin - 1); + string Arch = DebdeltaName.substr(NewEnd + 1, DebdeltaName.find(".", NewEnd + 1) - NewEnd - 1); + return PkgName + "_" + NewVersion + "_" + Arch + ".deb"; } /*}}}*/ @@ -99,14 +115,26 @@ public: */ bool Run(char const *debFile, char const *debdeltaFile) { - //_config->CndSet("Debug::pkgAcquire::RRed", "true"); + if (pkgInitConfig(*_config) == false || + pkgInitSystem(*_config,_system) == false) + { + std::cerr << "E: Could not initialize the system/configuration." << std::endl; + _error->DumpErrors(); + return 100; + } + _config->CndSet("Debug::pkgAcquire::Debdetla", "true"); FetchItem *test = new FetchItem; test->DestFile = debFile; test->Uri = debdeltaFile; test->FailIgnore = false; test->IndexFile = false; test->Next = 0; - return Fetch(test); + if (Fetch(test)) + { + std::cout << "Result-Deb: " << test->DestFile << std::endl; + return true; + } + return false; } }; @@ -120,8 +148,6 @@ public: */ int main(int argc, char *argv[]) { - // /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_amd64.deb - // /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_4.6.0-7_amd64.debdelta if (argc <= 1) { DebdeltaMethod Mth; diff --git a/test/methods/debdelta/test-signature b/test/methods/debdelta/test-signature new file mode 100755 index 000000000..f9fa678ff --- /dev/null +++ b/test/methods/debdelta/test-signature @@ -0,0 +1,47 @@ +#!/bin/sh +set -e + +deb=$1 + +verify_deb() { + [ "$deb" = "" ] && return + md5sum_1=$(apt-cache show `dpkg -I "$deb" | sed -n "s/Package: //p"` | sed -n "s/MD5sum: //p") + md5sum_2=$(md5sum "$deb" | gawk '{print $1}') + for s1 in $md5sum_1; do + for s2 in $md5sum_2; do + #echo "$s1 $s2" + if [ $s1 = $s2 ]; then + echo "[OK] $deb" + exit 0 + fi + done + done + echo "[NOT OK] $deb" + exit 1; +} + +usage() { + echo "Usage: test-signature <deb-file> <debdelta-file>" +} + +make_deb() { + if [ "$2" = "" ]; then + usage + exit 1 + fi + result_deb=$(LD_LIBRARY_PATH=../../../bin ../../../bin/methods/debdelta $1 $2 | sed -n "s/Result-Deb: //p") + deb=$result_deb + verify_deb +} + +testmethod() { + path="/var/cache/apt/archives/" + for d in $(dir $path); do + deb=$path$d + [ -d $deb ] && continue + runtest + done +} + +#testmethod +make_deb $1 $2 diff --git a/test/methods/debdelta/test.txt b/test/methods/debdelta/test.txt new file mode 100644 index 000000000..dbcae64d1 --- /dev/null +++ b/test/methods/debdelta/test.txt @@ -0,0 +1 @@ +./test-signature /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_amd64.deb /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_4.6.0-7_amd64.debdelta |