diff options
author | Ishan Jayawardena <udeshike@gmail.com> | 2011-06-15 14:19:00 +0530 |
---|---|---|
committer | Ishan Jayawardena <udeshike@gmail.com> | 2011-06-15 14:19:00 +0530 |
commit | 5da0f9fd194b76fd82482fbe533d963fc87f315d (patch) | |
tree | caa9413d7abf5d1557b123589e0cb1452acce20a /methods/debdelta.cc | |
parent | 9995c4a0bc2d8567ff9f11d338ad610754682372 (diff) |
revised the debdelta method
Diffstat (limited to 'methods/debdelta.cc')
-rw-r--r-- | methods/debdelta.cc | 95 |
1 files changed, 45 insertions, 50 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); } }; |