+ // The best hit
+ pkgSrcRecords::Parser *Last = 0;
+ unsigned long Offset = 0;
+ string Version;
+
+ // Iterate over all of the hits
+ pkgSrcRecords::Parser *Parse;
+ SrcRecs.Restart();
+ while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0)
+ {
+ string Ver = Parse->Version();
+ if (Last == 0 || pkgVersionCompare(Version,Ver) < 0)
+ {
+ Last = Parse;
+ Offset = Parse->Offset();
+ Version = Ver;
+ }
+ }
+
+ if (Last == 0)
+ return _error->Error("Unable to find a source package for %s",Src.c_str());
+
+ // Back track
+ vector<pkgSrcRecords::File> Lst;
+ if (Last->Jump(Offset) == false || Last->Files(Lst) == false)
+ return false;
+
+ // Load them into the fetcher
+ for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin();
+ I != Lst.end(); I++)
+ {
+ // Try to guess what sort of file it is we are getting.
+ string Comp;
+ if (I->Path.find(".dsc") != string::npos)
+ Comp = "dsc";
+ if (I->Path.find(".tar.gz") != string::npos)
+ Comp = "tar";
+ if (I->Path.find(".diff.gz") != string::npos)
+ Comp = "diff";
+
+ new pkgAcqFile(&Fetcher,Last->Source()->ArchiveURI(I->Path),
+ I->MD5Hash,I->Size,Last->Source()->SourceInfo(Src,
+ Last->Version(),Comp),Src);
+ }
+ }
+
+ // Display statistics
+ unsigned long FetchBytes = Fetcher.FetchNeeded();
+ unsigned long FetchPBytes = Fetcher.PartialPresent();
+ unsigned long DebBytes = Fetcher.TotalNeeded();
+
+ // Check for enough free space
+ struct statfs Buf;
+ string OutputDir = ".";
+ if (statfs(OutputDir.c_str(),&Buf) != 0)
+ return _error->Errno("statfs","Couldn't determine free space in %s",
+ OutputDir.c_str());
+ if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
+ return _error->Error("Sorry, you don't have enough free space in %s",
+ OutputDir.c_str());
+
+ // Number of bytes
+ c1out << "Need to get ";
+ if (DebBytes != FetchBytes)
+ c1out << SizeToStr(FetchBytes) << "b/" << SizeToStr(DebBytes) << 'b';
+ else
+ c1out << SizeToStr(DebBytes) << 'b';
+ c1out << " of source archives." << endl;
+
+ // Just print out the uris an exit if the --print-uris flag was used
+ if (_config->FindB("APT::Get::Print-URIs") == true)
+ {
+ pkgAcquire::UriIterator I = Fetcher.UriBegin();
+ for (; I != Fetcher.UriEnd(); I++)
+ cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
+ I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
+ return true;
+ }
+
+ // Run it
+ if (Fetcher.Run() == false)
+ return false;
+
+ // Print error messages
+ for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+ {
+ if ((*I)->Status == pkgAcquire::Item::StatDone &&
+ (*I)->Complete == true)
+ continue;
+
+ cerr << "Failed to fetch " << (*I)->DescURI() << endl;
+ cerr << " " << (*I)->ErrorText << endl;
+ }
+
+ return true;
+}
+ /*}}}*/
+