summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIshan Jayawardena <udeshike@gmail.com>2011-06-15 14:19:00 +0530
committerIshan Jayawardena <udeshike@gmail.com>2011-06-15 14:19:00 +0530
commit5da0f9fd194b76fd82482fbe533d963fc87f315d (patch)
treecaa9413d7abf5d1557b123589e0cb1452acce20a
parent9995c4a0bc2d8567ff9f11d338ad610754682372 (diff)
revised the debdelta method
-rw-r--r--methods/debdelta.cc95
-rwxr-xr-xtest/methods/debdelta/test-signature6
-rw-r--r--test/methods/debdelta/test.txt4
3 files changed, 51 insertions, 54 deletions
diff --git a/methods/debdelta.cc b/methods/debdelta.cc
index 81d9ed888..6c78c3990 100644
--- a/methods/debdelta.cc
+++ b/methods/debdelta.cc
@@ -21,36 +21,38 @@
/** \brief DebdeltaMethod - TODO: say something about debdelta here!
* */
class DebdeltaMethod : public pkgAcqMethod {
- bool Debug;
-
+ bool Debug;
+ string NewPackageName;
+ string DebdeltaFile;
+ string FromFile;
+ string ToFile;
protected:
// the main(i.e. most important) method of the debdelta method.
virtual bool Fetch(FetchItem *Itm);
public:
DebdeltaMethod() : pkgAcqMethod("1.1", SingleInstance | SendConfig) {};
- string GetNewPackageName(string debdeltaName);
+ void MakeToFile();
};
bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/
{
/// Testing only...
- FetchResult ResTest;
- ResTest.Filename = "/home/ishan/devel/apt/testrepo/binary/gcc-4.6-base_4.6.0-7_amd64.deb";
- URIDone(ResTest);
- return true;
+ //FetchResult ResTest;
+ //ResTest.Filename = "/home/ishan/devel/apt/testrepo/binary/gcc-4.6-base_4.6.0-7_amd64.deb";
+ //URIDone(ResTest);
+ //return true;
///
- Debug = _config->FindB("Debug::pkgAcquire::RRed", false);
+ Debug = _config->FindB("Debug::pkgAcquire::Debdelta", false);
+ FromFile = Itm->DestFile;
URI U(Itm->Uri);
- string OldDebFile = Itm->DestFile;
- string DebDeltaFile = U.Path;
- FetchResult Res;
- if (flExtension(OldDebFile) != ".deb" || !FileExists(OldDebFile))
- OldDebFile = "/";
- if (!FileExists(DebDeltaFile))
+ DebdeltaFile = U.Path;
+
+ if (flExtension(FromFile) != "deb" || !FileExists(FromFile))
+ FromFile = "/";
+ if (!FileExists(DebdeltaFile))
return _error->Error("[Debdelta] Could not find a debdelta file.");
- string NewDeb = GetNewPackageName(DebDeltaFile);
- Itm->DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + NewDeb;
- if (FileExists(Itm->DestFile))
+ MakeToFile();
+ if (FileExists(ToFile))
return _error->Error("[Debdelta] New .deb already exists.");
pid_t Process = ExecFork();
@@ -61,16 +63,16 @@ bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/
if (!FileExists(Args[0]))
return _error->Error("[Debdelta] Could not find debpatch.");
Args[1] = "-A";
- Args[2] = DebDeltaFile.c_str();
- Args[3] = OldDebFile.c_str();
- Args[4] = Itm->DestFile.c_str();
+ Args[2] = DebdeltaFile.c_str();
+ Args[3] = FromFile.c_str();
+ Args[4] = ToFile.c_str();
if (Debug == true)
{
std::cerr << "[Debdelta] Command:" << std::endl;
- std::cerr << Args[0] << " " << Args[1] << " " << Args[2] << " "
- << Args[3] << " " << Args[4] << std::endl;
+ std::cerr << Args[0] << " " << Args[1] << " " << Args[2] << " " << Args[3] << " "
+ << Args[4] << std::endl;
}
- std::cerr << "[Debdelta] Patching " << NewDeb << "..." << std::endl;
+ std::cerr << "[Debdelta] Patching " << ToFile << "..." << std::endl;
execv(Args[0], (char **)Args);
}
if (ExecWait(Process, "debpatch"))
@@ -78,36 +80,33 @@ bool DebdeltaMethod::Fetch(FetchItem *Itm) /*{{{*/
if (!FileExists(Itm->DestFile))
return _error->Error("[Debdelta] 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;
- Res.Filename = Itm->DestFile;
- URIDone(Res);
+ string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(ToFile);
+ Rename(ToFile, FinalFile);
+ ToFile = FinalFile;
+ FetchResult Res;
+ Res.Filename = ToFile;
+ if (Queue != 0)
+ URIDone(Res);
+ else
+ std::cout << "Filename: " << Res.Filename << std::endl;
return true;
}
- Itm->DestFile = OldDebFile;
-
return false;
}
-/**
- * \brief Receives a debdelta file name in the form of path/P_O_N_A.debdelta and constructs the name
- * of the deb with the newer version.
- * @param debdeltaName the name of the debdelta file.
- * @return path/P_N_A.deb
- */
-string DebdeltaMethod::GetNewPackageName(string DebdeltaName)
+
+void DebdeltaMethod::MakeToFile()
{
- int Slashpos = DebdeltaName.rfind("/", DebdeltaName.length() - 1);
- string Path = DebdeltaName.substr(0, Slashpos + 1);
- DebdeltaName = DebdeltaName.substr(Slashpos + 1, DebdeltaName.length() - 1);
+ int Slashpos = DebdeltaFile.rfind("/", DebdeltaFile.length() - 1);
+ string DebdeltaName = DebdeltaFile.substr(Slashpos + 1, DebdeltaFile.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";
+ ToFile = _config->FindDir("Dir::Cache::Archives") + "partial/"
+ + PkgName + "_" + NewVersion + "_" + Arch + ".deb";
}
/*}}}*/
@@ -121,7 +120,7 @@ public:
*
* \param base basename of all files involved in this debdelta test
*/
- bool Run(char const *debFile, char const *debdeltaFile)
+ bool Run(char const *DebdeltaFile, char const *FromFile)
{
if (pkgInitConfig(*_config) == false ||
pkgInitSystem(*_config,_system) == false)
@@ -132,17 +131,13 @@ public:
}
_config->CndSet("Debug::pkgAcquire::Debdetla", "true");
FetchItem *test = new FetchItem;
- test->DestFile = debFile;
- test->Uri = debdeltaFile;
+ test->DestFile = FromFile;
+ test->Uri = "debdelta://" + string(DebdeltaFile);
test->FailIgnore = false;
test->IndexFile = false;
test->Next = 0;
- if (Fetch(test))
- {
- std::cout << "Result-Deb: " << test->DestFile << std::endl;
- return true;
- }
- return false;
+
+ return Fetch(test);
}
};
diff --git a/test/methods/debdelta/test-signature b/test/methods/debdelta/test-signature
index f9fa678ff..952260322 100755
--- a/test/methods/debdelta/test-signature
+++ b/test/methods/debdelta/test-signature
@@ -5,7 +5,7 @@ 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_1=$(LD_LIBRARY_PATH=../../../bin ../../../bin/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
@@ -29,7 +29,7 @@ make_deb() {
usage
exit 1
fi
- result_deb=$(LD_LIBRARY_PATH=../../../bin ../../../bin/methods/debdelta $1 $2 | sed -n "s/Result-Deb: //p")
+ result_deb=$(LD_LIBRARY_PATH=../../../bin ../../../bin/methods/debdelta $1 $2 | sed -n "s/Filename: //p")
deb=$result_deb
verify_deb
}
@@ -44,4 +44,4 @@ testmethod() {
}
#testmethod
-make_deb $1 $2
+make_deb $1 $2 \ No newline at end of file
diff --git a/test/methods/debdelta/test.txt b/test/methods/debdelta/test.txt
index dbcae64d1..8b5f8f189 100644
--- a/test/methods/debdelta/test.txt
+++ b/test/methods/debdelta/test.txt
@@ -1 +1,3 @@
-./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
+./test-signature /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_4.6.0-7_amd64.debdelta /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_amd64.deb
+
+sudo LD_LIBRARY_PATH=.. ./debdelta /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_4.6.0-7_amd64.debdelta /home/ishan/devel/apt/testrepo/testitems/cpp-4.6_4.6.0-2_amd64.deb