diff options
Diffstat (limited to 'methods')
-rw-r--r-- | methods/copy.cc | 38 | ||||
-rw-r--r-- | methods/http.cc | 24 | ||||
-rw-r--r-- | methods/https.cc | 12 |
3 files changed, 47 insertions, 27 deletions
diff --git a/methods/copy.cc b/methods/copy.cc index d59f032ff..cc0ee6554 100644 --- a/methods/copy.cc +++ b/methods/copy.cc @@ -16,6 +16,7 @@ #include <apt-pkg/acquire-method.h> #include <apt-pkg/error.h> #include <apt-pkg/hashes.h> +#include <apt-pkg/configuration.h> #include <string> #include <sys/stat.h> @@ -27,19 +28,35 @@ class CopyMethod : public pkgAcqMethod { virtual bool Fetch(FetchItem *Itm); - + void CalculateHashes(FetchResult &Res); + public: - CopyMethod() : pkgAcqMethod("1.0",SingleInstance) {}; + CopyMethod() : pkgAcqMethod("1.0",SingleInstance|SendConfig) {}; }; +void CopyMethod::CalculateHashes(FetchResult &Res) +{ + // For gzip indexes we need to look inside the gzip for the hash + // We can not use the extension here as its not used in partial + // on a IMS hit + FileFd::OpenMode OpenMode = FileFd::ReadOnly; + if (_config->FindB("Acquire::GzipIndexes", false) == true) + OpenMode = FileFd::ReadOnlyGzip; + + Hashes Hash; + FileFd Fd(Res.Filename, OpenMode); + Hash.AddFD(Fd); + Res.TakeHashes(Hash); +} + // CopyMethod::Fetch - Fetch a file /*{{{*/ // --------------------------------------------------------------------- /* */ bool CopyMethod::Fetch(FetchItem *Itm) { URI Get = Itm->Uri; - std::string File = Get.Path; + std::string File = Get.Host + Get.Path; // To account for relative paths // Stat the file and send a start message struct stat Buf; @@ -53,7 +70,15 @@ bool CopyMethod::Fetch(FetchItem *Itm) Res.LastModified = Buf.st_mtime; Res.IMSHit = false; URIStart(Res); - + + // when the files are identical, just compute the hashes + if(File == Itm->DestFile) + { + CalculateHashes(Res); + URIDone(Res); + return true; + } + // See if the file exists FileFd From(File,FileFd::ReadOnly); FileFd To(Itm->DestFile,FileFd::WriteAtomic); @@ -82,10 +107,7 @@ bool CopyMethod::Fetch(FetchItem *Itm) if (utimes(Res.Filename.c_str(), times) != 0) return _error->Errno("utimes",_("Failed to set modification time")); - Hashes Hash; - FileFd Fd(Res.Filename, FileFd::ReadOnly); - Hash.AddFD(Fd); - Res.TakeHashes(Hash); + CalculateHashes(Res); URIDone(Res); return true; diff --git a/methods/http.cc b/methods/http.cc index ed6e3517d..d3a5d718f 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -667,7 +667,7 @@ void HttpMethod::SendReq(FetchItem *Itm) URI Uri = Itm->Uri; // The HTTP server expects a hostname with a trailing :port - char Buf[1000]; + string Buf; string ProperHost; if (Uri.Host.find(':') != string::npos) @@ -676,14 +676,10 @@ void HttpMethod::SendReq(FetchItem *Itm) ProperHost = Uri.Host; if (Uri.Port != 0) { - sprintf(Buf,":%u",Uri.Port); + strprintf(Buf,":%u",Uri.Port); ProperHost += Buf; } - // Just in case. - if (Itm->Uri.length() >= sizeof(Buf)) - abort(); - /* RFC 2616 ยง5.1.2 requires absolute URIs for requests to proxies, but while its a must for all servers to accept absolute URIs, it is assumed clients will sent an absolute path for non-proxies */ @@ -701,25 +697,27 @@ void HttpMethod::SendReq(FetchItem *Itm) in 1.1, can cause problems with proxies, and we are an HTTP/1.1 client anyway. C.f. https://tools.ietf.org/wg/httpbis/trac/ticket/158 */ - sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n", + strprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n", requesturi.c_str(),ProperHost.c_str()); // generate a cache control header (if needed) if (_config->FindB("Acquire::http::No-Cache",false) == true) { - strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n"); + Buf += "Cache-Control: no-cache\r\nPragma: no-cache\r\n"; } else { if (Itm->IndexFile == true) { - sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n", + string Tmp; + strprintf(Tmp,"Cache-Control: max-age=%u\r\n", _config->FindI("Acquire::http::Max-Age",0)); + Buf += Tmp; } else { if (_config->FindB("Acquire::http::No-Store",false) == true) - strcat(Buf,"Cache-Control: no-store\r\n"); + Buf += "Cache-Control: no-store\r\n"; } } @@ -733,7 +731,7 @@ void HttpMethod::SendReq(FetchItem *Itm) size_t const filepos = Itm->Uri.find_last_of('/'); string const file = Itm->Uri.substr(filepos + 1); if (flExtension(file) == file) - strcat(Buf,"Accept: text/*\r\n"); + Buf += "Accept: text/*\r\n"; } string Req = Buf; @@ -743,7 +741,7 @@ void HttpMethod::SendReq(FetchItem *Itm) if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0) { // In this case we send an if-range query with a range header - sprintf(Buf,"Range: bytes=%lli-\r\nIf-Range: %s\r\n",(long long)SBuf.st_size, + strprintf(Buf,"Range: bytes=%lli-\r\nIf-Range: %s\r\n",(long long)SBuf.st_size, TimeRFC1123(SBuf.st_mtime).c_str()); Req += Buf; } @@ -751,7 +749,7 @@ void HttpMethod::SendReq(FetchItem *Itm) { if (Itm->LastModified != 0) { - sprintf(Buf,"If-Modified-Since: %s\r\n",TimeRFC1123(Itm->LastModified).c_str()); + strprintf(Buf,"If-Modified-Since: %s\r\n",TimeRFC1123(Itm->LastModified).c_str()); Req += Buf; } } diff --git a/methods/https.cc b/methods/https.cc index c4aff8f38..087604b6d 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -124,13 +124,13 @@ void HttpsMethod::SetupProxy() /*{{{*/ if (UseProxy == "DIRECT") return; - if (UseProxy.empty() == false) + // Parse no_proxy, a comma (,) separated list of domains we don't want to use + // a proxy for so we stop right here if it is in the list + if (getenv("no_proxy") != 0 && CheckDomainList(ServerName.Host,getenv("no_proxy")) == true) + return; + + if (UseProxy.empty() == true) { - // Parse no_proxy, a comma (,) separated list of domains we don't want to use - // a proxy for so we stop right here if it is in the list - if (getenv("no_proxy") != 0 && CheckDomainList(ServerName.Host,getenv("no_proxy")) == true) - return; - } else { const char* result = getenv("https_proxy"); // FIXME: Fall back to http_proxy is to remain compatible with // existing setups and behaviour of apt.conf. This should be |