1 // Include Files /*{{{*/
4 #include <apt-pkg/acquire-item.h>
5 #include <apt-pkg/acquire.h>
6 #include <apt-pkg/algorithms.h>
7 #include <apt-pkg/aptconfiguration.h>
8 #include <apt-pkg/cachefile.h>
9 #include <apt-pkg/cacheiterators.h>
10 #include <apt-pkg/cacheset.h>
11 #include <apt-pkg/cmndline.h>
12 #include <apt-pkg/configuration.h>
13 #include <apt-pkg/depcache.h>
14 #include <apt-pkg/error.h>
15 #include <apt-pkg/fileutl.h>
16 #include <apt-pkg/hashes.h>
17 #include <apt-pkg/indexfile.h>
18 #include <apt-pkg/metaindex.h>
19 #include <apt-pkg/pkgcache.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/srcrecords.h>
22 #include <apt-pkg/strutl.h>
23 #include <apt-pkg/version.h>
24 #include <apt-pkg/policy.h>
26 #include <apt-private/private-cachefile.h>
27 #include <apt-private/private-cacheset.h>
28 #include <apt-private/private-download.h>
29 #include <apt-private/private-install.h>
30 #include <apt-private/private-source.h>
32 #include <apt-pkg/debindexfile.h>
50 // GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/
51 static pkgCache::RlsFileIterator
GetReleaseFileForSourceRecord(CacheFile
&CacheFile
,
52 pkgSourceList
const * const SrcList
, pkgSrcRecords::Parser
const * const Parse
)
54 // try to find release
55 const pkgIndexFile
& CurrentIndexFile
= Parse
->Index();
57 for (pkgSourceList::const_iterator S
= SrcList
->begin();
58 S
!= SrcList
->end(); ++S
)
60 std::vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
61 for (std::vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
62 IF
!= Indexes
->end(); ++IF
)
64 if (&CurrentIndexFile
== (*IF
))
65 return (*S
)->FindInCache(CacheFile
, false);
68 return pkgCache::RlsFileIterator(CacheFile
);
71 // FindSrc - Find a source record /*{{{*/
72 static pkgSrcRecords::Parser
*FindSrc(const char *Name
,
73 pkgSrcRecords
&SrcRecs
,std::string
&Src
,
76 if (Cache
.BuildCaches(false) == false)
78 std::string VerTag
, UserRequestedVerTag
;
79 std::string ArchTag
= "";
80 std::string RelTag
= _config
->Find("APT::Default-Release");
81 std::string TmpSrc
= Name
;
84 size_t found
= TmpSrc
.find_last_of("/");
85 if (found
!= std::string::npos
)
87 RelTag
= TmpSrc
.substr(found
+1);
88 TmpSrc
= TmpSrc
.substr(0,found
);
90 // extract the version
91 found
= TmpSrc
.find_last_of("=");
92 if (found
!= std::string::npos
)
94 VerTag
= UserRequestedVerTag
= TmpSrc
.substr(found
+1);
95 TmpSrc
= TmpSrc
.substr(0,found
);
98 found
= TmpSrc
.find_last_of(":");
99 if (found
!= std::string::npos
)
101 ArchTag
= TmpSrc
.substr(found
+1);
102 TmpSrc
= TmpSrc
.substr(0,found
);
105 /* Lookup the version of the package we would install if we were to
106 install a version and determine the source package name, then look
107 in the archive for a source package of the same name. */
108 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
109 pkgCache::PkgIterator Pkg
;
111 Pkg
= Cache
.GetPkgCache()->FindPkg(TmpSrc
, ArchTag
);
113 Pkg
= Cache
.GetPkgCache()->FindPkg(TmpSrc
);
115 // if we can't find a package but the user qualified with a arch,
117 if (Pkg
.end() && ArchTag
!= "")
120 _error
->Error(_("Can not find a package for architecture '%s'"),
125 if (MatchSrcOnly
== false && Pkg
.end() == false)
127 if(VerTag
!= "" || RelTag
!= "" || ArchTag
!= "")
130 // we have a default release, try to locate the pkg. we do it like
131 // this because GetCandidateVer() will not "downgrade", that means
132 // "apt-get source -t stable apt" won't work on a unstable system
133 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; ++Ver
)
135 // try first only exact matches, later fuzzy matches
136 if (Ver
.end() == true)
141 Ver
= Pkg
.VersionList();
142 // exit right away from the Pkg.VersionList() loop if we
143 // don't have any versions
144 if (Ver
.end() == true)
148 // ignore arches that are not for us
149 if (ArchTag
!= "" && Ver
.Arch() != ArchTag
)
152 // pick highest version for the arch unless the user wants
154 if (ArchTag
!= "" && VerTag
== "" && RelTag
== "")
155 if(Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) < 0)
156 VerTag
= Ver
.VerStr();
158 // We match against a concrete version (or a part of this version)
159 if (VerTag
.empty() == false &&
160 (fuzzy
== true || Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
161 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
164 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
165 VF
.end() == false; ++VF
)
167 /* If this is the status file, and the current version is not the
168 version in the status file (ie it is not installed, or somesuch)
169 then it is not a candidate for installation, ever. This weeds
170 out bogus entries that may be due to config-file states, or
172 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
173 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
176 // or we match against a release
177 if(VerTag
.empty() == false ||
178 (VF
.File().Archive() != 0 && VF
.File().Archive() == RelTag
) ||
179 (VF
.File().Codename() != 0 && VF
.File().Codename() == RelTag
))
181 // the Version we have is possibly fuzzy or includes binUploads,
182 // so we use the Version of the SourcePkg (empty if same as package)
183 Src
= Ver
.SourcePkgName();
184 VerTag
= Ver
.SourceVerStr();
188 if (Src
.empty() == false)
193 if (Src
.empty() == true && ArchTag
.empty() == false)
195 if (VerTag
.empty() == false)
196 _error
->Error(_("Can not find a package '%s' with version '%s'"),
197 Pkg
.FullName().c_str(), VerTag
.c_str());
198 if (RelTag
.empty() == false)
199 _error
->Error(_("Can not find a package '%s' with release '%s'"),
200 Pkg
.FullName().c_str(), RelTag
.c_str());
206 if (Src
.empty() == true)
208 // if we don't have found a fitting package yet so we will
209 // choose a good candidate and proceed with that.
210 // Maybe we will find a source later on with the right VerTag
212 if (Cache
.BuildPolicy() == false)
214 pkgPolicy
* Policy
= dynamic_cast<pkgPolicy
*>(Cache
.GetPolicy());
215 if (Policy
== nullptr)
217 _error
->Fatal("Implementation error: dynamic up-casting policy engine failed in FindSrc!");
220 pkgCache::VerIterator
const Ver
= Policy
->GetCandidateVer(Pkg
);
221 if (Ver
.end() == false)
223 if (strcmp(Ver
.SourcePkgName(),Ver
.ParentPkg().Name()) != 0)
224 Src
= Ver
.SourcePkgName();
225 if (VerTag
.empty() == true && strcmp(Ver
.SourceVerStr(),Ver
.VerStr()) != 0)
226 VerTag
= Ver
.SourceVerStr();
231 if (Src
.empty() == true)
237 /* if we have a source pkg name, make sure to only search
238 for srcpkg names, otherwise apt gets confused if there
239 is a binary package "pkg1" and a source package "pkg1"
240 with the same name but that comes from different packages */
244 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
249 pkgSrcRecords::Parser
*Last
= 0;
250 unsigned long Offset
= 0;
252 pkgSourceList
const * const SrcList
= Cache
.GetSourceList();
254 /* Iterate over all of the hits, which includes the resulting
255 binary packages in the search */
256 pkgSrcRecords::Parser
*Parse
;
260 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
262 const std::string Ver
= Parse
->Version();
264 // See if we need to look for a specific release tag
265 if (RelTag
.empty() == false && UserRequestedVerTag
.empty() == true)
267 pkgCache::RlsFileIterator
const Rls
= GetReleaseFileForSourceRecord(Cache
, SrcList
, Parse
);
268 if (Rls
.end() == false)
270 if ((Rls
->Archive
!= 0 && RelTag
!= Rls
.Archive()) &&
271 (Rls
->Codename
!= 0 && RelTag
!= Rls
.Codename()))
276 // Ignore all versions which doesn't fit
277 if (VerTag
.empty() == false &&
278 Cache
->VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
281 // Newer version or an exact match? Save the hit
282 if (Last
== 0 || Cache
->VS().CmpVersion(Version
,Ver
) < 0) {
284 Offset
= Parse
->Offset();
288 // was the version check above an exact match?
289 // If so, we don't need to look further
290 if (VerTag
.empty() == false && (VerTag
== Ver
))
293 if (UserRequestedVerTag
== "" && Version
!= "" && RelTag
!= "")
294 ioprintf(c1out
, "Selected version '%s' (%s) for %s\n",
295 Version
.c_str(), RelTag
.c_str(), Src
.c_str());
297 if (Last
!= 0 || VerTag
.empty() == true)
299 _error
->Error(_("Can not find version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
303 if (Last
== 0 || Last
->Jump(Offset
) == false)
309 // DoSource - Fetch a source archive /*{{{*/
310 // ---------------------------------------------------------------------
311 /* Fetch souce packages */
318 bool DoSource(CommandLine
&CmdL
)
321 if (Cache
.Open(false) == false)
324 if (CmdL
.FileSize() <= 1)
325 return _error
->Error(_("Must specify at least one package to fetch source for"));
327 // Read the source list
328 if (Cache
.BuildSourceList() == false)
330 pkgSourceList
*List
= Cache
.GetSourceList();
332 // Create the text record parsers
333 pkgSrcRecords
SrcRecs(*List
);
334 if (_error
->PendingError() == true)
337 std::unique_ptr
<DscFile
[]> Dsc(new DscFile
[CmdL
.FileSize()]);
339 // insert all downloaded uris into this set to avoid downloading them
341 std::set
<std::string
> queued
;
343 // Diff only mode only fetches .diff files
344 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
345 // Tar only mode only fetches .tar files
346 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
347 // Dsc only mode only fetches .dsc files
348 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
350 // Load the requestd sources into the fetcher
351 aptAcquireWithTextStatus Fetcher
;
353 std::vector
<std::string
> UntrustedList
;
354 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
357 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
359 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
362 if (Last
->Index().IsTrusted() == false)
363 UntrustedList
.push_back(Src
);
365 std::string srec
= Last
->AsStr();
366 std::string::size_type pos
= srec
.find("\nVcs-");
367 while (pos
!= std::string::npos
)
369 pos
+= strlen("\nVcs-");
370 std::string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
373 pos
= srec
.find("\nVcs-", pos
);
376 pos
+= vcs
.length()+2;
377 std::string::size_type epos
= srec
.find("\n", pos
);
378 std::string
const uri
= srec
.substr(pos
,epos
-pos
);
379 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
380 "the '%s' version control system at:\n"
382 Src
.c_str(), vcs
.c_str(), uri
.c_str());
385 vcscmd
= "bzr branch " + uri
;
386 else if (vcs
== "Git")
387 vcscmd
= "git clone " + uri
;
389 if (vcscmd
.empty() == false)
390 ioprintf(c1out
,_("Please use:\n%s\n"
391 "to retrieve the latest (possibly unreleased) "
392 "updates to the package.\n"),
398 std::vector
<pkgSrcRecords::File2
> Lst
;
399 if (Last
->Files2(Lst
) == false) {
403 // Load them into the fetcher
404 for (std::vector
<pkgSrcRecords::File2
>::const_iterator I
= Lst
.begin();
407 // Try to guess what sort of file it is we are getting.
408 if (I
->Type
== "dsc")
410 Dsc
[J
].Package
= Last
->Package();
411 Dsc
[J
].Version
= Last
->Version();
412 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
415 // Handle the only options so that multiple can be used at once
416 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
418 if ((diffOnly
== true && I
->Type
== "diff") ||
419 (tarOnly
== true && I
->Type
== "tar") ||
420 (dscOnly
== true && I
->Type
== "dsc"))
421 ; // Fine, we want this file downloaded
426 // don't download the same uri twice (should this be moved to
427 // the fetcher interface itself?)
428 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
430 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
432 // check if we have a file with that md5 sum already localy
433 std::string localFile
= flNotDir(I
->Path
);
434 if (FileExists(localFile
) == true)
435 if(I
->Hashes
.VerifyFile(localFile
) == true)
437 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
442 // see if we have a hash (Acquire::ForceHash is the only way to have none)
443 if (I
->Hashes
.usable() == false && _config
->FindB("APT::Get::AllowUnauthenticated",false) == false)
445 ioprintf(c1out
, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
450 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
451 I
->Hashes
, I
->FileSize
, Last
->Index().SourceInfo(*Last
,*I
), Src
);
455 // Display statistics
456 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
457 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
458 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
460 if (CheckFreeSpaceBeforeDownload(".", (FetchBytes
- FetchPBytes
)) == false)
464 if (DebBytes
!= FetchBytes
)
465 //TRANSLATOR: The required space between number and unit is already included
466 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
467 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
468 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
470 //TRANSLATOR: The required space between number and unit is already included
471 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
472 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
473 SizeToStr(DebBytes
).c_str());
475 if (_config
->FindB("APT::Get::Simulate",false) == true)
477 for (unsigned I
= 0; I
!= J
; I
++)
478 ioprintf(std::cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
482 // Just print out the uris an exit if the --print-uris flag was used
483 if (_config
->FindB("APT::Get::Print-URIs") == true)
485 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
486 for (; I
!= Fetcher
.UriEnd(); ++I
)
487 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
488 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
492 // check authentication status of the source as well
493 if (UntrustedList
.empty() == false && AuthPrompt(UntrustedList
, false) == false)
498 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
500 return _error
->Error(_("Failed to fetch some archives."));
503 if (_config
->FindB("APT::Get::Download-only",false) == true)
505 c1out
<< _("Download complete and in download only mode") << std::endl
;
509 // Unpack the sources
510 pid_t Process
= ExecFork();
514 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
515 for (unsigned I
= 0; I
!= J
; ++I
)
517 std::string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
519 // Diff only mode only fetches .diff files
520 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
521 _config
->FindB("APT::Get::Tar-Only",false) == true ||
522 Dsc
[I
].Dsc
.empty() == true)
525 // See if the package is already unpacked
527 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
528 S_ISDIR(Stat
.st_mode
) != 0)
530 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
536 std::string
const sourceopts
= _config
->Find("DPkg::Source-Options", "-x");
538 strprintf(S
, "%s %s %s",
539 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
540 sourceopts
.c_str(), Dsc
[I
].Dsc
.c_str());
541 if (system(S
.c_str()) != 0)
543 fprintf(stderr
, _("Unpack command '%s' failed.\n"), S
.c_str());
544 fprintf(stderr
, _("Check if the 'dpkg-dev' package is installed.\n"));
549 // Try to compile it with dpkg-buildpackage
550 if (_config
->FindB("APT::Get::Compile",false) == true)
552 std::string buildopts
= _config
->Find("APT::Get::Host-Architecture");
553 if (buildopts
.empty() == false)
554 buildopts
= "-a" + buildopts
+ " ";
556 // get all active build profiles
557 std::string
const profiles
= APT::Configuration::getBuildProfilesString();
558 if (profiles
.empty() == false)
559 buildopts
.append(" -P").append(profiles
).append(" ");
561 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
563 // Call dpkg-buildpackage
565 strprintf(S
, "cd %s && %s %s",
567 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
570 if (system(S
.c_str()) != 0)
572 fprintf(stderr
, _("Build command '%s' failed.\n"), S
.c_str());
581 return ExecWait(Process
, "dpkg-source");
584 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
585 // ---------------------------------------------------------------------
586 /* This function will look at the build depends list of the given source
587 package and install the necessary packages to make it true, or fail. */
588 static std::vector
<pkgSrcRecords::Parser::BuildDepRec
> GetBuildDeps(pkgSrcRecords::Parser
* const Last
,
589 char const * const Src
, bool const StripMultiArch
, std::string
const &hostArch
)
591 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
592 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
593 if (hostArch
.empty() == false)
595 std::string nativeArch
= _config
->Find("APT::Architecture");
596 _config
->Set("APT::Architecture", hostArch
);
597 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
598 _config
->Set("APT::Architecture", nativeArch
);
599 if (Success
== false)
601 _error
->Error(_("Unable to get build-dependency information for %s"), Src
);
605 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
607 _error
->Error(_("Unable to get build-dependency information for %s"), Src
);
611 if (BuildDeps
.empty() == true)
612 ioprintf(c1out
,_("%s has no build depends.\n"), Src
);
616 static void WriteBuildDependencyPackage(std::ostringstream
&buildDepsPkgFile
,
617 std::string
const &PkgName
, std::string
const &Arch
,
618 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> const &Dependencies
)
620 buildDepsPkgFile
<< "Package: " << PkgName
<< "\n"
621 << "Architecture: " << Arch
<< "\n"
624 std::string depends
, conflicts
;
625 for (auto const &dep
: Dependencies
)
628 if (dep
.Type
== pkgSrcRecords::Parser::BuildConflict
|| dep
.Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
633 type
->append(" ").append(dep
.Package
);
634 if (dep
.Version
.empty() == false)
635 type
->append(" (").append(pkgCache::CompTypeDeb(dep
.Op
)).append(" ").append(dep
.Version
).append(")");
636 if ((dep
.Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
638 type
->append("\n |");
643 if (depends
.empty() == false)
644 buildDepsPkgFile
<< "Depends:\n" << depends
;
645 if (conflicts
.empty() == false)
646 buildDepsPkgFile
<< "Conflicts:\n" << conflicts
;
647 buildDepsPkgFile
<< "\n";
649 bool DoBuildDep(CommandLine
&CmdL
)
652 std::vector
<char const *> VolatileCmdL
;
653 Cache
.GetSourceList()->AddVolatileFiles(CmdL
, &VolatileCmdL
);
655 _config
->Set("APT::Install-Recommends", false);
657 if (CmdL
.FileSize() <= 1 && VolatileCmdL
.empty())
658 return _error
->Error(_("Must specify at least one package to check builddeps for"));
661 std::string hostArch
= _config
->Find("APT::Get::Host-Architecture");
662 if (hostArch
.empty() == false)
664 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
665 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
666 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
667 StripMultiArch
= false;
670 StripMultiArch
= true;
672 std::ostringstream buildDepsPkgFile
;
673 std::vector
<std::pair
<std::string
,std::string
>> pseudoPkgs
;
674 // deal with the build essentials first
676 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
677 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
680 for (; Opts
; Opts
= Opts
->Next
)
682 if (Opts
->Value
.empty() == true)
685 pkgSrcRecords::Parser::BuildDepRec rec
;
686 rec
.Package
= Opts
->Value
;
687 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
689 BuildDeps
.push_back(rec
);
691 std::string
const pseudo
= "builddeps:essentials";
692 std::string
const nativeArch
= _config
->Find("APT::Architecture");
693 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, nativeArch
, BuildDeps
);
694 pseudoPkgs
.emplace_back(pseudo
, nativeArch
);
697 // Read the source list
698 if (Cache
.BuildSourceList() == false)
700 pkgSourceList
*List
= Cache
.GetSourceList();
701 std::string
const pseudoArch
= hostArch
.empty() ? _config
->Find("APT::Architecture") : hostArch
;
703 // FIXME: Avoid volatile sources == cmdline assumption
705 auto const VolatileSources
= List
->GetVolatileFiles();
706 if (VolatileSources
.size() == VolatileCmdL
.size())
708 for (size_t i
= 0; i
< VolatileSources
.size(); ++i
)
710 char const * const Src
= VolatileCmdL
[i
];
711 if (DirectoryExists(Src
))
712 ioprintf(c1out
, _("Note, using directory '%s' to get the build dependencies\n"), Src
);
714 ioprintf(c1out
, _("Note, using file '%s' to get the build dependencies\n"), Src
);
715 std::unique_ptr
<pkgSrcRecords::Parser
> Last(VolatileSources
[i
]->CreateSrcParser());
717 return _error
->Error(_("Unable to find a source package for %s"), Src
);
719 std::string
const pseudo
= std::string("builddeps:") + Src
;
720 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, pseudoArch
,
721 GetBuildDeps(Last
.get(), Src
, StripMultiArch
, hostArch
));
722 pseudoPkgs
.emplace_back(pseudo
, pseudoArch
);
726 return _error
->Error("Implementation error: Volatile sources (%lu) and"
727 "commandline elements (%lu) do not match!", VolatileSources
.size(),
728 VolatileCmdL
.size());
731 if (CmdL
.FileList
[1] != 0)
733 // Create the text record parsers
734 pkgSrcRecords
SrcRecs(*List
);
735 if (_error
->PendingError() == true)
737 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; ++I
)
740 pkgSrcRecords::Parser
* const Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
742 return _error
->Error(_("Unable to find a source package for %s"), *I
);
744 std::string
const pseudo
= std::string("builddeps:") + Src
;
745 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, pseudoArch
,
746 GetBuildDeps(Last
, Src
.c_str(), StripMultiArch
, hostArch
));
747 pseudoPkgs
.emplace_back(pseudo
, pseudoArch
);
751 Cache
.AddIndexFile(new debStringPackageIndex(buildDepsPkgFile
.str()));
753 bool WantLock
= _config
->FindB("APT::Get::Print-URIs", false) == false;
754 if (Cache
.Open(WantLock
) == false)
756 pkgProblemResolver
Fix(Cache
.GetDepCache());
758 APT::PackageVector removeAgain
;
760 pkgDepCache::ActionGroup
group(Cache
);
761 TryToInstall
InstallAction(Cache
, &Fix
, false);
762 for (auto const &pkg
: pseudoPkgs
)
764 pkgCache::PkgIterator
const Pkg
= Cache
->FindPkg(pkg
.first
, pkg
.second
);
767 Cache
->SetCandidateVersion(Pkg
.VersionList());
768 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
769 removeAgain
.push_back(Pkg
);
771 InstallAction
.doAutoInstall();
773 OpTextProgress
Progress(*_config
);
774 bool const resolver_fail
= Fix
.Resolve(true, &Progress
);
775 if (resolver_fail
== false && Cache
->BrokenCount() == 0)
777 if (CheckNothingBroken(Cache
) == false)
780 if (DoAutomaticRemove(Cache
) == false)
783 pkgDepCache::ActionGroup
group(Cache
);
784 for (auto const &pkg
: removeAgain
)
785 Cache
->MarkDelete(pkg
, false, 0, true);
789 if (_error
->PendingError() || InstallPackages(Cache
, false, true) == false)
790 return _error
->Error(_("Failed to process build dependencies"));