- ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
- localFile.c_str());
- continue;
- }
-
- new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
- I->Hashes, I->Size, Last->Index().SourceInfo(*Last,*I), Src);
- }
- }
-
- // Display statistics
- unsigned long long FetchBytes = Fetcher.FetchNeeded();
- unsigned long long FetchPBytes = Fetcher.PartialPresent();
- unsigned long long DebBytes = Fetcher.TotalNeeded();
-
- if (CheckFreeSpaceBeforeDownload(".", (FetchBytes - FetchPBytes)) == false)
- return false;
-
- // Number of bytes
- if (DebBytes != FetchBytes)
- //TRANSLATOR: The required space between number and unit is already included
- // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
- ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
- SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
- else
- //TRANSLATOR: The required space between number and unit is already included
- // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
- ioprintf(c1out,_("Need to get %sB of source archives.\n"),
- SizeToStr(DebBytes).c_str());
-
- if (_config->FindB("APT::Get::Simulate",false) == true)
- {
- for (unsigned I = 0; I != J; I++)
- ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
- return true;
- }
-
- // 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->HashSum() << endl;
- return true;
- }
-
- // Disable drop-privs if "_apt" can not write to the target dir
- CheckDropPrivsMustBeDisabled(Fetcher);
-
- // check authentication status of the source as well
- if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
- return false;
-
- // Run it
- bool Failed = false;
- if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
- {
- return _error->Error(_("Failed to fetch some archives."));
- }
-
- if (_config->FindB("APT::Get::Download-only",false) == true)
- {
- c1out << _("Download complete and in download only mode") << endl;
- return true;
- }
-
- // Unpack the sources
- pid_t Process = ExecFork();
-
- if (Process == 0)
- {
- bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
- for (unsigned I = 0; I != J; ++I)
- {
- string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
-
- // Diff only mode only fetches .diff files
- if (_config->FindB("APT::Get::Diff-Only",false) == true ||
- _config->FindB("APT::Get::Tar-Only",false) == true ||
- Dsc[I].Dsc.empty() == true)
- continue;
-
- // See if the package is already unpacked
- struct stat Stat;
- if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
- S_ISDIR(Stat.st_mode) != 0)
- {
- ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
- Dir.c_str());
- }
- else
- {
- // Call dpkg-source
- std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x");
- std::string S;
- strprintf(S, "%s %s %s",
- _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
- sourceopts.c_str(), Dsc[I].Dsc.c_str());
- if (system(S.c_str()) != 0)
- {
- fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str());
- fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n"));
- _exit(1);
- }
- }
-
- // Try to compile it with dpkg-buildpackage
- if (_config->FindB("APT::Get::Compile",false) == true)
- {
- string buildopts = _config->Find("APT::Get::Host-Architecture");
- if (buildopts.empty() == false)
- buildopts = "-a" + buildopts + " ";
-
- // get all active build profiles
- std::string const profiles = APT::Configuration::getBuildProfilesString();
- if (profiles.empty() == false)
- buildopts.append(" -P").append(profiles).append(" ");
-
- buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
-
- // Call dpkg-buildpackage
- std::string S;
- strprintf(S, "cd %s && %s %s",
- Dir.c_str(),
- _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
- buildopts.c_str());
-
- if (system(S.c_str()) != 0)
- {
- fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str());
- _exit(1);
- }
- }
- }
-
- _exit(0);
- }
-
- // Wait for the subprocess
- int Status = 0;
- while (waitpid(Process,&Status,0) != Process)
- {
- if (errno == EINTR)
- continue;
- return _error->Errno("waitpid","Couldn't wait for subprocess");
- }
-
- if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
- return _error->Error(_("Child process failed"));
-
- return true;
-}
- /*}}}*/
-// DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
-// ---------------------------------------------------------------------
-/* This function will look at the build depends list of the given source
- package and install the necessary packages to make it true, or fail. */
-static bool DoBuildDep(CommandLine &CmdL)
-{
- CacheFile Cache;
-
- _config->Set("APT::Install-Recommends", false);
-
- if (Cache.Open(true) == false)
- return false;
-
- if (CmdL.FileSize() <= 1)
- return _error->Error(_("Must specify at least one package to check builddeps for"));
-
- // Read the source list
- if (Cache.BuildSourceList() == false)
- return false;
- pkgSourceList *List = Cache.GetSourceList();
-
- // Create the text record parsers
-#if APT_PKG_ABI < 413
- pkgRecords Recs(Cache);
-#endif
- pkgSrcRecords SrcRecs(*List);
- if (_error->PendingError() == true)
- return false;
-
- bool StripMultiArch;
- string hostArch = _config->Find("APT::Get::Host-Architecture");
- if (hostArch.empty() == false)
- {
- std::vector<std::string> archs = APT::Configuration::getArchitectures();
- if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
- return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
- StripMultiArch = false;
- }
- else
- StripMultiArch = true;
-
- unsigned J = 0;
- for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
- {
- string Src;
- pkgSrcRecords::Parser *Last = 0;
-
- // an unpacked debian source tree
- using APT::String::Startswith;
- if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
- DirectoryExists(*I))
- {
- ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
- // FIXME: how can we make this more elegant?
- std::string TypeName = "debian/control File Source Index";
- pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
- if(Type != NULL)
- Last = Type->CreateSrcPkgParser(*I);
- }
- // if its a local file (e.g. .dsc) use this
- else if (FileExists(*I))
- {
- ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
-
- // see if we can get a parser for this pkgIndexFile type
- string TypeName = flExtension(*I) + " File Source Index";
- pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
- if(Type != NULL)
- Last = Type->CreateSrcPkgParser(*I);
- } else {
- // normal case, search the cache for the source file
-#if APT_PKG_ABI >= 413
- Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
- Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
- }
-
- if (Last == 0)
- return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
-
- // Process the build-dependencies
- vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
- // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
- if (hostArch.empty() == false)
- {
- std::string nativeArch = _config->Find("APT::Architecture");
- _config->Set("APT::Architecture", hostArch);
- bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
- _config->Set("APT::Architecture", nativeArch);
- if (Success == false)
- return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
- }
- else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
- return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
-
- // Also ensure that build-essential packages are present
- Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
- if (Opts)
- Opts = Opts->Child;
- for (; Opts; Opts = Opts->Next)
- {
- if (Opts->Value.empty() == true)
- continue;
-
- pkgSrcRecords::Parser::BuildDepRec rec;
- rec.Package = Opts->Value;
- rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
- rec.Op = 0;
- BuildDeps.push_back(rec);
- }
-
- if (BuildDeps.empty() == true)
- {
- ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
- continue;
- }
-
- // Install the requested packages
- vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
- pkgProblemResolver Fix(Cache);
- bool skipAlternatives = false; // skip remaining alternatives in an or group
- for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
- {
- bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
-
- if (skipAlternatives == true)
- {
- /*
- * if there are alternatives, we've already picked one, so skip
- * the rest
- *
- * TODO: this means that if there's a build-dep on A|B and B is
- * installed, we'll still try to install A; more importantly,
- * if A is currently broken, we cannot go back and try B. To fix
- * this would require we do a Resolve cycle for each package we
- * add to the install list. Ugh
- */
- if (!hasAlternatives)
- skipAlternatives = false; // end of or group
- continue;
- }
-
- if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
- (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
- {
- pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
- // Build-conflicts on unknown packages are silently ignored
- if (Grp.end() == true)
- continue;
-
- for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))