summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire-item.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/acquire-item.cc')
-rw-r--r--apt-pkg/acquire-item.cc302
1 files changed, 300 insertions, 2 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 215615bdd..b85e5d19b 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -727,7 +727,7 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long Size,string Md5Hash, /*
// rred excepts the patch as $FinalFile.ed
Rename(DestFile,FinalFile+".ed");
-
+ std::clog << " Sending to rred method FinalFile: " << FinalFile << std::endl;
if(Debug)
std::clog << "Sending to rred method: " << FinalFile << std::endl;
@@ -2066,7 +2066,305 @@ string pkgAcqFile::Custom600Headers()
return "\nIndex-File: true";
return "";
}
- /*}}}*/
+/*}}}*/
+
+pkgAcqDebdelta::pkgAcqDebdelta(pkgAcquire *Owner,pkgSourceList *Sources,
+ pkgRecords *Recs,pkgCache::VerIterator const &Version,
+ string &StoreFilename) :
+ Item(Owner), Version(Version), Sources(Sources), Recs(Recs),
+ StoreFilename(StoreFilename), Vf(Version.FileList()),
+ Trusted(false)
+{
+ DebdeltaName = string(Version.ParentPkg().Name()) + "_"
+ + string(Version.ParentPkg().CurVersion()) + "_"
+ + string(Version.ParentPkg().CandVersion()) + "_"
+ + string(Version.Arch()) + ".debdelta";
+ Retries = _config->FindI("Acquire::Retries",0);
+ Debug = true;
+ if (Version.Arch() == 0)
+ {
+ _error->Error(_("I wasn't able to locate a file for the %s package. "
+ "This might mean you need to manually fix this package. "
+ "(due to missing arch)"),
+ Version.ParentPkg().Name());
+ return;
+ }
+
+ /* We need to find a filename to determine the extension. We make the
+ assumption here that all the available sources for this version share
+ the same extension.. */
+ // Skip not source sources, they do not have file fields.
+ for (; Vf.end() == false; Vf++)
+ {
+ if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
+ continue;
+ break;
+ }
+
+ // Does not really matter here.. we are going to fail out below
+ if (Vf.end() != true)
+ {
+ // If this fails to get a file name we will bomb out below.
+ pkgRecords::Parser &Parse = Recs->Lookup(Vf);
+ if (_error->PendingError() == true)
+ return;
+
+ DebdeltaName = StoreFilename = QuoteString(DebdeltaName, ":");
+ DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename);
+ }
+
+ // check if we have one trusted source for the package. if so, switch
+ // to "TrustedOnly" mode
+ for (pkgCache::VerFileIterator i = Version.FileList(); i.end() == false; i++)
+ {
+ pkgIndexFile *Index;
+ if (Sources->FindIndex(i.File(),Index) == false)
+ continue;
+ if (_config->FindB("Debug::pkgAcquire::Auth", false))
+ {
+ std::cerr << "Checking index: " << Index->Describe()
+ << "(Trusted=" << Index->IsTrusted() << ")\n";
+ }
+ if (Index->IsTrusted()) {
+ Trusted = true;
+ break;
+ }
+ }
+
+ // "allow-unauthenticated" restores apts old fetching behaviour
+ // that means that e.g. unauthenticated file:// uris are higher
+ // priority than authenticated http:// uris
+ if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
+ Trusted = false;
+ if (Debug) {
+ std::cerr << "\n[Debdelta] pkgAcqDebdelta::pkgAcqDebdelta()" << std::endl;
+ std::cerr << " DebdeltaName : " << DebdeltaName << std::endl;
+ std::cerr << " StoreFilename: " << StoreFilename << std::endl;
+ std::cerr << " DestFile : " << DestFile << std::endl;
+ }
+ DebdeltaStatus = Fetching;
+ if (QueueNext() == false && _error->PendingError() == false)
+ _error->Error(_("I wasn't able to locate a file for the %s package. "
+ "This might mean you need to manually fix this package."),
+ Version.ParentPkg().Name());
+}
+
+bool pkgAcqDebdelta::QueueNext()
+{
+ string const ForceHash = _config->Find("Acquire::ForceHash");
+
+ for (; Vf.end() == false; Vf++)
+ {
+ // Ignore not source sources
+ if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
+ continue;
+
+ // Try to cross match against the source list
+ pkgIndexFile *Index;
+ if (Sources->FindIndex(Vf.File(),Index) == false)
+ continue;
+
+ // only try to get a trusted package from another source if that source
+ // is also trusted
+ if(Trusted && !Index->IsTrusted())
+ continue;
+
+ // Grab the text package record
+ pkgRecords::Parser &Parse = Recs->Lookup(Vf);
+ if (_error->PendingError() == true)
+ return false;
+
+ string PkgFile = Parse.FileName();
+ //std::cerr << " PkgFile:" << PkgFile << std::endl;
+ if (ForceHash.empty() == false)
+ {
+ if(stringcasecmp(ForceHash, "sha256") == 0)
+ ExpectedHash = HashString("SHA256", Parse.SHA256Hash());
+ else if (stringcasecmp(ForceHash, "sha1") == 0)
+ ExpectedHash = HashString("SHA1", Parse.SHA1Hash());
+ else
+ ExpectedHash = HashString("MD5Sum", Parse.MD5Hash());
+ }
+ else
+ {
+ string Hash;
+ if ((Hash = Parse.SHA256Hash()).empty() == false)
+ ExpectedHash = HashString("SHA256", Hash);
+ else if ((Hash = Parse.SHA1Hash()).empty() == false)
+ ExpectedHash = HashString("SHA1", Hash);
+ else
+ ExpectedHash = HashString("MD5Sum", Parse.MD5Hash());
+ }
+ if (PkgFile.empty() == true)
+ return _error->Error(_("The package index files are corrupted. No Filename: "
+ "field for package %s."),
+ Version.ParentPkg().Name());
+ // See if we already have the deb
+ FileSize = Version->Size;
+ string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
+ struct stat Buf;
+ if (stat(FinalFile.c_str(),&Buf) == 0)
+ {
+ if (Debug)
+ std::cerr << "[Debdelta] File already exists. " << FinalFile << std::endl;
+ // TODO: check if this ok. Make sure the size matches
+ if ((unsigned)Buf.st_size == Version->Size)
+ {
+ Complete = true;
+ Local = true;
+ Status = StatDone;
+ DebdeltaStatus = Completed;
+ StoreFilename = DestFile = FinalFile;
+ return true;
+ }
+ /* Hmm, we have a file and its size does not match, this means it is
+ an old style mismatched arch */
+ unlink(FinalFile.c_str());
+ }
+
+ // Create the item
+ Local = false;
+ // See if we already have the debdelta in the partial dir.
+ if (FileExists(DestFile))
+ {
+ // TODO: verify the sum/size of it.
+ if (Debug)
+ std::cerr << "[Debdelta] File already exists. " << DestFile << std::endl;
+ Desc.URI = "debdelta:" + DestFile;
+ Mode = "debdelta";
+ DebdeltaStatus = Patching;
+ Local = true;
+ }
+ else
+ {
+ Desc.URI = flNotFile(Index->ArchiveURI(PkgFile)) + DebdeltaName;
+ ReplaceURI();
+ }
+ Desc.Description = "[Debdelta] " + Index->ArchiveInfo(Version);
+ Desc.Owner = this;
+ Desc.ShortDesc = "[Debdelta] " + string(Version.ParentPkg().Name());
+ if (Debug) {
+ std::cerr << "[Debdelta] pkgAcqDebdelta::QueueNext()" << std::endl;
+ std::cerr << " DestFile : " << DestFile << std::endl;
+ std::cerr << " Desc.URI : " << Desc.URI << std::endl;
+ std::cerr << " StoreFileName: " << StoreFilename << std::endl;
+ }
+ Vf++;
+ QueueURI(Desc);
+ return true;
+ }
+ return false;
+}
+
+void pkgAcqDebdelta::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
+{
+ if (Debug) {
+ std::cerr << "\n[Debdelta] Failed to download " << Desc.URI << std::endl;
+ std::cerr << "[Debdelta] Message:\n" << Message << std::endl;
+ }
+ // TODO: find out what went wrong and display to the user
+ new pkgAcqArchive(Owner, Sources, Recs, Version, StoreFilename);
+ Complete = false;
+ Status = StatError;
+ DebdeltaStatus = FetchingFailure;
+ Item::Failed(Message, Cnf);
+ Dequeue();
+}
+
+void pkgAcqDebdelta::Done(string Message,unsigned long Size,string Hash,
+ pkgAcquire::MethodConfig *Cnf)
+{
+ // TODO: there must be two stages within this method.
+ // one for downloading debdelta. another for verifying the resulting .deb
+ if (Debug) std::cerr << "[Debdelta] pkgAcqDebdelta::Done() state: " << DebdeltaStatus << std::endl;
+ // Grab the output filename
+ string FileName = LookupTag(Message,"Filename");
+ if (Debug) {
+ std::cerr << " StoreFileName: " << StoreFilename
+ << "\n DestFile : " << DestFile
+ << "\n Desc.URI : " << Desc.URI
+ << "\n FileName : " << FileName << std::endl;
+ }
+ if (DebdeltaStatus == Patching)
+ {
+ if (Debug) std::cerr << "[Debdelta] Patching Done. Verifying "<< FileName << "..." << std::endl;
+ if (ExpectedHash.toStr() != Hash)
+ {
+ Status = StatError;
+ ErrorText = _("[Debdelta] Hash Sum mismatch");
+ if(FileExists(DestFile))
+ if (!Local)
+ Rename(DestFile, DestFile + ".FAILED");
+ //return; // TODO: UNCOMMENT
+ }
+ // Check the size
+ if (Size != Version->Size)
+ {
+ Status = StatError;
+ ErrorText = _("[Debdelta] Size mismatch");
+ //return; // TODO: UNCOMMEnT
+ }
+ DebdeltaStatus = Completed;
+ Complete = true;
+ Status = StatDone;
+ StoreFilename = FileName;
+ Item::Done(Message,Size,Hash,Cnf);
+ return;
+ }
+ // TODO: Check the sum/size
+ //std::cerr << "[Debdelta] Verifying " << DestFile << std::endl;
+ if (FileName.empty() == true)
+ {
+ Status = StatError;
+ ErrorText = "[Debdelta] Method gave a blank filename";
+ return;
+ }
+ if (FileName != DestFile) // this is set in the file/http methods
+ {
+ // file => FileName != DestFile (i.e. FileName is the local file)
+ // http => FileName == DestFile (i.e. FileName is some local place. may be within "partial" dir)
+ Local = true;
+ }
+ DebdeltaStatus = Patching;
+ Rename(DestFile, FileName);
+ DestFile = StoreFilename = FileName;
+ chmod(DestFile.c_str(), 0644);
+ Desc.URI = "debdelta:" + StoreFilename;
+ Mode = "debdelta";
+ QueueURI(Desc);
+}
+
+void pkgAcqDebdelta::Finished()
+{
+ if (Debug)
+ std::cerr << "[Debdelta] pkgAcqDebdelta::Finished() state: " << DebdeltaStatus << std::endl;
+ if (Status == pkgAcquire::Item::StatDone &&
+ Complete == true)
+ return;
+ StoreFilename = string();
+}
+
+bool pkgAcqDebdelta::ReplaceURI()
+{
+ const Configuration::Item* item = _config->Tree("Aquire::Debdelta::Replace-Rule");
+ for (item = item->Child; item != 0; item = item->Next)
+ {
+ size_t pos = 0;
+ // see if the Des.URI is available in the URI-Space
+ if ((pos = Desc.URI.find(item->Tag, pos)) != std::string::npos)
+ {
+ Desc.URI.replace(pos, item->Tag.length(), item->Value);
+ if (Debug)
+ {
+ std::cerr << "[Debdelta] Replaced " << item->Tag << " => " << item->Value << std::endl;
+ std::cerr << " New URI: " << Desc.URI << std::endl;
+ }
+ return true;
+ }
+ }
+ return _error->Error("[Debdelta] Could not find a replacement URI.");
+}
+
bool IndexTarget::IsOptional() const {
if (strncmp(ShortDesc.c_str(), "Translation", 11) != 0)
return false;