summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc56
-rw-r--r--apt-pkg/acquire-item.h4
-rw-r--r--apt-pkg/acquire-method.cc21
-rw-r--r--apt-pkg/acquire-method.h15
-rw-r--r--apt-pkg/init.cc1
5 files changed, 81 insertions, 16 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 94288a132..3be7878bf 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -63,6 +63,7 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
{
Status = StatIdle;
ErrorText = LookupTag(Message,"Message");
+ UsedMirror = LookupTag(Message,"UsedMirror");
if (QueueCounter <= 1)
{
/* This indicates that the file is not available right now but might
@@ -79,6 +80,13 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
Status = StatError;
Dequeue();
}
+
+ // report mirror failure back to LP if we actually use a mirror
+ string FailReason = LookupTag(Message, "FailReason");
+ if(FailReason.size() != 0)
+ ReportMirrorFailure(FailReason);
+ else
+ ReportMirrorFailure(ErrorText);
}
/*}}}*/
// Acquire::Item::Start - Item has begun to download /*{{{*/
@@ -100,6 +108,7 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string,
{
// We just downloaded something..
string FileName = LookupTag(Message,"Filename");
+ UsedMirror = LookupTag(Message,"UsedMirror");
if (Complete == false && FileName == DestFile)
{
if (Owner->Log != 0)
@@ -108,7 +117,6 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string,
if (FileSize == 0)
FileSize= Size;
-
Status = StatDone;
ErrorText = string();
Owner->Dequeue(this);
@@ -131,6 +139,49 @@ void pkgAcquire::Item::Rename(string From,string To)
}
/*}}}*/
+void pkgAcquire::Item::ReportMirrorFailure(string FailCode)
+{
+ // we only act if a mirror was used at all
+ if(UsedMirror.empty())
+ return;
+#if 0
+ std::cerr << "\nReportMirrorFailure: "
+ << UsedMirror
+ << " Uri: " << DescURI()
+ << " FailCode: "
+ << FailCode << std::endl;
+#endif
+ const char *Args[40];
+ unsigned int i = 0;
+ string report = _config->Find("Methods::Mirror::ProblemReporting",
+ "/usr/lib/apt/apt-report-mirror-failure");
+ if(!FileExists(report))
+ return;
+ Args[i++] = report.c_str();
+ Args[i++] = UsedMirror.c_str();
+ Args[i++] = DescURI().c_str();
+ Args[i++] = FailCode.c_str();
+ Args[i++] = NULL;
+ pid_t pid = ExecFork();
+ if(pid < 0)
+ {
+ _error->Error("ReportMirrorFailure Fork failed");
+ return;
+ }
+ else if(pid == 0)
+ {
+ execvp(Args[0], (char**)Args);
+ std::cerr << "Could not exec " << Args[0] << std::endl;
+ _exit(100);
+ }
+ if(!ExecWait(pid, "report-mirror-failure"))
+ {
+ _error->Warning("Couldn't report problem to '%s'",
+ _config->Find("Methods::Mirror::ProblemReporting").c_str());
+ }
+}
+
+
// AcqIndex::AcqIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* The package file is added to the queue and a second class is
@@ -176,7 +227,6 @@ string pkgAcqIndex::Custom600Headers()
struct stat Buf;
if (stat(Final.c_str(),&Buf) != 0)
return "\nIndex-File: true";
-
return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
}
/*}}}*/
@@ -235,6 +285,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5,
Status = StatAuthError;
ErrorText = _("MD5Sum mismatch");
Rename(DestFile,DestFile + ".FAILED");
+ ReportMirrorFailure("HashChecksumFailure");
return;
}
// Done, move it into position
@@ -757,6 +808,7 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
}
// gpgv method failed
+ ReportMirrorFailure("GPGFailure");
_error->Warning("GPG error: %s: %s",
Desc.Description.c_str(),
LookupTag(Message,"Message").c_str());
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index 3a0a690e1..f659bb459 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -57,6 +57,7 @@ class pkgAcquire::Item
unsigned long ID;
bool Complete;
bool Local;
+ string UsedMirror;
// Number of queues we are inserted into
unsigned int QueueCounter;
@@ -79,6 +80,9 @@ class pkgAcquire::Item
pkgAcquire *GetOwner() {return Owner;};
virtual bool IsTrusted() {return false;};
+ // report mirror problems
+ void ReportMirrorFailure(string FailCode);
+
Item(pkgAcquire *Owner);
virtual ~Item();
};
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index 41b832f3b..180b52ad7 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -99,12 +99,11 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
}
char S[1024];
+ char *End = S;
if (Queue != 0)
{
- snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n"
- "Message: %s %s\n",Queue->Uri.c_str(),Err.c_str(),
- FailExtra.c_str());
-
+ End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n"
+ "Message: %s %s\n",Queue->Uri.c_str(), Err.c_str(), IP.c_str());
// Dequeue
FetchItem *Tmp = Queue;
Queue = Queue->Next;
@@ -113,10 +112,14 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
QueueBack = Queue;
}
else
- snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: <UNKNOWN>\n"
- "Message: %s %s\n",Err.c_str(),
- FailExtra.c_str());
-
+ {
+ End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: <UNKNOWN>\n"
+ "Message: %s\n",Err.c_str());
+ }
+ if(FailReason.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"FailReason: %s\n",FailReason.c_str());
+ if (UsedMirror.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
// Set the transient flag
if (Transient == true)
strcat(S,"Transient-Failure: true\n\n");
@@ -182,6 +185,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str());
if (Res.SHA1Sum.empty() == false)
End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str());
+ if (UsedMirror.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
if (Res.GPGVOutput.size() > 0)
End += snprintf(End,sizeof(S)-50 - (End - S),"GPGVOutput:\n");
for (vector<string>::iterator I = Res.GPGVOutput.begin();
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index f46209d12..20691cc2c 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -54,7 +54,9 @@ class pkgAcqMethod
vector<string> Messages;
FetchItem *Queue;
FetchItem *QueueBack;
- string FailExtra;
+ string FailReason;
+ string UsedMirror;
+ string IP;
// Handlers for messages
virtual bool Configuration(string Message);
@@ -63,14 +65,14 @@ class pkgAcqMethod
// Outgoing messages
void Fail(bool Transient = false);
inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
- void Fail(string Why, bool Transient = false);
- void URIStart(FetchResult &Res);
- void URIDone(FetchResult &Res,FetchResult *Alt = 0);
+ virtual void Fail(string Why, bool Transient = false);
+ virtual void URIStart(FetchResult &Res);
+ virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
+
bool MediaFail(string Required,string Drive);
virtual void Exit() {};
public:
-
enum CnfFlags {SingleInstance = (1<<0),
Pipeline = (1<<1), SendConfig = (1<<2),
LocalOnly = (1<<3), NeedsCleanup = (1<<4),
@@ -80,7 +82,8 @@ class pkgAcqMethod
void Status(const char *Format,...);
int Run(bool Single = false);
- inline void SetFailExtraMsg(string Msg) {FailExtra = Msg;};
+ inline void SetFailReason(string Msg) {FailReason = Msg;};
+ inline void SetIP(string aIP) {IP = aIP;};
pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
virtual ~pkgAcqMethod() {};
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index 579a19ab9..0be0aee98 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -56,6 +56,7 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::State::lists","lists/");
Cnf.Set("Dir::State::cdroms","cdroms.list");
+ Cnf.Set("Dir::State::mirrors","mirrors/");
// Cache
Cnf.Set("Dir::Cache","var/cache/apt/");