summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc79
-rw-r--r--apt-pkg/acquire-item.h10
-rw-r--r--apt-pkg/init.cc24
3 files changed, 75 insertions, 38 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 39ae327cb..ffbe66d7d 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -551,13 +551,24 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
if(comprExt.empty())
{
// autoselect the compression method
- if(FileExists("/bin/bzip2"))
- CompressionExtension = ".bz2";
- else
- CompressionExtension = ".gz";
- } else {
- CompressionExtension = (comprExt == "plain" ? "" : comprExt);
+ Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+ if (Opts != 0)
+ Opts = Opts->Child;
+
+ const char dirBin[] = "Dir::Bin::";
+ for (; Opts != 0; Opts = Opts->Next)
+ {
+ if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
+ continue;
+ const string bin = _config->FindFile(string(dirBin).append(Opts->Value).c_str(),"");
+ if (bin != "" && !FileExists(bin))
+ continue;
+ comprExt = '.' + Opts->Tag;
+ break;
+ }
}
+ CompressionExtension = ((comprExt == "plain" || comprExt == ".") ? "" : comprExt);
+
Desc.URI = URI + CompressionExtension;
Desc.Description = URIDesc;
@@ -584,24 +595,32 @@ string pkgAcqIndex::Custom600Headers()
/*}}}*/
void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
{
- bool descChanged = false;
- // no .bz2 found, retry with .gz
- if(Desc.URI.substr(Desc.URI.size()-3) == "bz2") {
- Desc.URI = Desc.URI.substr(0,Desc.URI.size()-3) + "gz";
-
- new pkgAcqIndex(Owner, RealURI, Desc.Description,Desc.ShortDesc,
- ExpectedHash, string(".gz"));
- descChanged = true;
- }
- // no .gz found, retry with uncompressed
- else if(Desc.URI.substr(Desc.URI.size()-2) == "gz") {
- Desc.URI = Desc.URI.substr(0,Desc.URI.size()-2);
+ Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+ if (Opts != 0)
+ Opts = Opts->Child;
+
+ const char dirBin[] = "Dir::Bin::";
+ for (; Opts != 0; Opts = Opts->Next)
+ {
+ if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
+ continue;
+
+ // jump over all already checked compression types
+ const unsigned int nameLen = Desc.URI.size() - Opts->Tag.size();
+ if(Desc.URI.substr(nameLen) != Opts->Tag || Opts->Next == 0)
+ continue;
+
+ // check if we need an external binary for this compression type
+ const string bin = _config->FindFile(string(dirBin).append(Opts->Next->Value).c_str(),"");
+ if (bin != "" && !FileExists(bin))
+ continue;
+
+ // retry with the next extension
+ Desc.URI = Desc.URI.substr(0, nameLen) + Opts->Next->Tag;
+
+ new pkgAcqIndex(Owner, RealURI, Desc.Description, Desc.ShortDesc,
+ ExpectedHash, string(".").append(Opts->Next->Tag));
- new pkgAcqIndex(Owner, RealURI, Desc.Description,Desc.ShortDesc,
- ExpectedHash, string("plain"));
- descChanged = true;
- }
- if (descChanged) {
Status = StatDone;
Complete = false;
Dequeue();
@@ -698,11 +717,11 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash,
Local = true;
string compExt = flExtension(flNotDir(URI(Desc.URI).Path));
- const char *decompProg;
- if(compExt == "bz2")
- decompProg = "bzip2";
- else if(compExt == "gz")
- decompProg = "gzip";
+ string decompProg;
+
+ // get the binary name for your used compression type
+ decompProg = _config->Find(string("Acquire::CompressionTypes::").append(compExt),"");
+ if(decompProg.empty() == false);
// flExtensions returns the full name if no extension is found
// this is why we have this complicated compare operation here
// FIMXE: add a new flJustExtension() that return "" if no
@@ -717,9 +736,9 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash,
Decompression = true;
DestFile += ".decomp";
- Desc.URI = string(decompProg) + ":" + FileName;
+ Desc.URI = decompProg + ":" + FileName;
QueueURI(Desc);
- Mode = decompProg;
+ Mode = decompProg.c_str();
}
/*}}}*/
// AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index 36a926a0f..3f073de5b 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -540,7 +540,9 @@ class pkgAcqIndex : public pkgAcquire::Item
*
* \param compressExt The compression-related extension with which
* this index file should be downloaded, or "" to autodetect
- * (".bz2" is used if bzip2 is installed, ".gz" otherwise).
+ * Compression types can be set with config Acquire::CompressionTypes,
+ * default is ".lzma" or ".bz2" (if the needed binaries are present)
+ * fallback is ".gz" or none.
*/
pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
string ShortDesc, HashString ExpectedHash, string compressExt="");
@@ -569,12 +571,6 @@ class pkgAcqIndexTrans : public pkgAcqIndex
* \param URIDesc A "URI-style" description of this index file.
*
* \param ShortDesc A brief description of this index file.
- *
- * \param ExpectedHash The expected hashsum of this index file.
- *
- * \param compressExt The compression-related extension with which
- * this index file should be downloaded, or "" to autodetect
- * (".bz2" is used if bzip2 is installed, ".gz" otherwise).
*/
pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
string ShortDesc);
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index 63caade36..46017bf0c 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -103,7 +103,29 @@ bool pkgInitConfig(Configuration &Cnf)
if (Res == false)
return false;
-
+
+ // we load all config files, now check the configs and setup post-defaults:
+ // * check for CompressionTypes setup
+ {
+ Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+ if (Opts != 0)
+ Opts = Opts->Child;
+ bool foundLzma=false, foundBzip2=false, foundGzip=false;
+ for (; Opts != 0; Opts = Opts->Next)
+ {
+ if (Opts->Value == "lzma") foundLzma = true;
+ else if (Opts->Value == "bz2") foundBzip2 = true;
+ else if (Opts->Value == "gz") foundGzip = true;
+ }
+ if (!foundBzip2) Cnf.Set("Acquire::CompressionTypes::bz2","bzip2");
+ if (!foundLzma) Cnf.Set("Acquire::CompressionTypes::lzma","lzma");
+ if (!foundGzip) Cnf.Set("Acquire::CompressionTypes::gz","gzip");
+ Cnf.CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
+ Cnf.CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+ }
+
+
+
if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
Cnf.Dump();