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
.GetPkgCache()->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
.GetPkgCache()->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
.GetPkgCache()->VS
->CmpVersion(VerTag
, Ver
) != 0) // exact match
281 // Newer version or an exact match? Save the hit
282 if (Last
== 0 || Cache
.GetPkgCache()->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
)
320 if (CmdL
.FileSize() <= 1)
321 return _error
->Error(_("Must specify at least one package to fetch source for"));
324 // Read the source list
325 if (Cache
.BuildSourceList() == false)
327 pkgSourceList
*List
= Cache
.GetSourceList();
329 // Create the text record parsers
330 pkgSrcRecords
SrcRecs(*List
);
331 if (_error
->PendingError() == true)
334 std::unique_ptr
<DscFile
[]> Dsc(new DscFile
[CmdL
.FileSize()]);
336 // insert all downloaded uris into this set to avoid downloading them
338 std::set
<std::string
> queued
;
340 // Diff only mode only fetches .diff files
341 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
342 // Tar only mode only fetches .tar files
343 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
344 // Dsc only mode only fetches .dsc files
345 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
347 // Load the requestd sources into the fetcher
348 aptAcquireWithTextStatus Fetcher
;
350 std::vector
<std::string
> UntrustedList
;
351 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
354 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
356 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
359 if (Last
->Index().IsTrusted() == false)
360 UntrustedList
.push_back(Src
);
362 std::string srec
= Last
->AsStr();
363 std::string::size_type pos
= srec
.find("\nVcs-");
364 while (pos
!= std::string::npos
)
366 pos
+= strlen("\nVcs-");
367 std::string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
370 pos
= srec
.find("\nVcs-", pos
);
373 pos
+= vcs
.length()+2;
374 std::string::size_type epos
= srec
.find("\n", pos
);
375 std::string
const uri
= srec
.substr(pos
,epos
-pos
);
376 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
377 "the '%s' version control system at:\n"
379 Src
.c_str(), vcs
.c_str(), uri
.c_str());
382 vcscmd
= "bzr branch " + uri
;
383 else if (vcs
== "Git")
384 vcscmd
= "git clone " + uri
;
386 if (vcscmd
.empty() == false)
387 ioprintf(c1out
,_("Please use:\n%s\n"
388 "to retrieve the latest (possibly unreleased) "
389 "updates to the package.\n"),
395 std::vector
<pkgSrcRecords::File2
> Lst
;
396 if (Last
->Files2(Lst
) == false) {
400 // Load them into the fetcher
401 for (std::vector
<pkgSrcRecords::File2
>::const_iterator I
= Lst
.begin();
404 // Try to guess what sort of file it is we are getting.
405 if (I
->Type
== "dsc")
407 Dsc
[J
].Package
= Last
->Package();
408 Dsc
[J
].Version
= Last
->Version();
409 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
412 // Handle the only options so that multiple can be used at once
413 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
415 if ((diffOnly
== true && I
->Type
== "diff") ||
416 (tarOnly
== true && I
->Type
== "tar") ||
417 (dscOnly
== true && I
->Type
== "dsc"))
418 ; // Fine, we want this file downloaded
423 // don't download the same uri twice (should this be moved to
424 // the fetcher interface itself?)
425 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
427 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
429 // check if we have a file with that md5 sum already localy
430 std::string localFile
= flNotDir(I
->Path
);
431 if (FileExists(localFile
) == true)
432 if(I
->Hashes
.VerifyFile(localFile
) == true)
434 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
439 // see if we have a hash (Acquire::ForceHash is the only way to have none)
440 if (I
->Hashes
.usable() == false && _config
->FindB("APT::Get::AllowUnauthenticated",false) == false)
442 ioprintf(c1out
, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
447 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
448 I
->Hashes
, I
->FileSize
, Last
->Index().SourceInfo(*Last
,*I
), Src
);
452 // Display statistics
453 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
454 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
455 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
457 if (CheckFreeSpaceBeforeDownload(".", (FetchBytes
- FetchPBytes
)) == false)
461 if (DebBytes
!= FetchBytes
)
462 //TRANSLATOR: The required space between number and unit is already included
463 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
464 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
465 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
467 //TRANSLATOR: The required space between number and unit is already included
468 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
469 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
470 SizeToStr(DebBytes
).c_str());
472 if (_config
->FindB("APT::Get::Simulate",false) == true)
474 for (unsigned I
= 0; I
!= J
; I
++)
475 ioprintf(std::cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
479 // Just print out the uris an exit if the --print-uris flag was used
480 if (_config
->FindB("APT::Get::Print-URIs") == true)
482 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
483 for (; I
!= Fetcher
.UriEnd(); ++I
)
484 std::cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
485 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << std::endl
;
489 // check authentication status of the source as well
490 if (UntrustedList
.empty() == false && AuthPrompt(UntrustedList
, false) == false)
495 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
497 return _error
->Error(_("Failed to fetch some archives."));
500 if (_config
->FindB("APT::Get::Download-only",false) == true)
502 c1out
<< _("Download complete and in download only mode") << std::endl
;
506 // Unpack the sources
507 pid_t Process
= ExecFork();
511 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
512 for (unsigned I
= 0; I
!= J
; ++I
)
514 std::string Dir
= Dsc
[I
].Package
+ '-' + Cache
.GetPkgCache()->VS
->UpstreamVersion(Dsc
[I
].Version
.c_str());
516 // Diff only mode only fetches .diff files
517 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
518 _config
->FindB("APT::Get::Tar-Only",false) == true ||
519 Dsc
[I
].Dsc
.empty() == true)
522 // See if the package is already unpacked
524 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
525 S_ISDIR(Stat
.st_mode
) != 0)
527 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
533 std::string
const sourceopts
= _config
->Find("DPkg::Source-Options", "-x");
535 strprintf(S
, "%s %s %s",
536 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
537 sourceopts
.c_str(), Dsc
[I
].Dsc
.c_str());
538 if (system(S
.c_str()) != 0)
540 fprintf(stderr
, _("Unpack command '%s' failed.\n"), S
.c_str());
541 fprintf(stderr
, _("Check if the 'dpkg-dev' package is installed.\n"));
546 // Try to compile it with dpkg-buildpackage
547 if (_config
->FindB("APT::Get::Compile",false) == true)
549 std::string buildopts
= _config
->Find("APT::Get::Host-Architecture");
550 if (buildopts
.empty() == false)
551 buildopts
= "-a" + buildopts
+ " ";
553 // get all active build profiles
554 std::string
const profiles
= APT::Configuration::getBuildProfilesString();
555 if (profiles
.empty() == false)
556 buildopts
.append(" -P").append(profiles
).append(" ");
558 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
560 // Call dpkg-buildpackage
562 strprintf(S
, "cd %s && %s %s",
564 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
567 if (system(S
.c_str()) != 0)
569 fprintf(stderr
, _("Build command '%s' failed.\n"), S
.c_str());
578 return ExecWait(Process
, "dpkg-source");
581 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
582 // ---------------------------------------------------------------------
583 /* This function will look at the build depends list of the given source
584 package and install the necessary packages to make it true, or fail. */
585 static std::vector
<pkgSrcRecords::Parser::BuildDepRec
> GetBuildDeps(pkgSrcRecords::Parser
* const Last
,
586 char const * const Src
, bool const StripMultiArch
, std::string
const &hostArch
)
588 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
589 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
590 if (hostArch
.empty() == false)
592 std::string nativeArch
= _config
->Find("APT::Architecture");
593 _config
->Set("APT::Architecture", hostArch
);
594 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
595 _config
->Set("APT::Architecture", nativeArch
);
596 if (Success
== false)
598 _error
->Error(_("Unable to get build-dependency information for %s"), Src
);
602 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
604 _error
->Error(_("Unable to get build-dependency information for %s"), Src
);
608 if (BuildDeps
.empty() == true)
609 ioprintf(c1out
,_("%s has no build depends.\n"), Src
);
613 static void WriteBuildDependencyPackage(std::ostringstream
&buildDepsPkgFile
,
614 std::string
const &PkgName
, std::string
const &Arch
,
615 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> const &Dependencies
)
617 buildDepsPkgFile
<< "Package: " << PkgName
<< "\n"
618 << "Architecture: " << Arch
<< "\n"
621 std::string depends
, conflicts
;
622 for (auto const &dep
: Dependencies
)
625 if (dep
.Type
== pkgSrcRecords::Parser::BuildConflict
|| dep
.Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
630 type
->append(" ").append(dep
.Package
);
631 if (dep
.Version
.empty() == false)
632 type
->append(" (").append(pkgCache::CompTypeDeb(dep
.Op
)).append(" ").append(dep
.Version
).append(")");
633 if ((dep
.Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
635 type
->append("\n |");
640 if (depends
.empty() == false)
641 buildDepsPkgFile
<< "Depends:\n" << depends
;
642 if (conflicts
.empty() == false)
643 buildDepsPkgFile
<< "Conflicts:\n" << conflicts
;
644 buildDepsPkgFile
<< "\n";
646 bool DoBuildDep(CommandLine
&CmdL
)
649 std::vector
<char const *> VolatileCmdL
;
650 Cache
.GetSourceList()->AddVolatileFiles(CmdL
, &VolatileCmdL
);
652 _config
->Set("APT::Install-Recommends", false);
654 if (CmdL
.FileSize() <= 1 && VolatileCmdL
.empty())
655 return _error
->Error(_("Must specify at least one package to check builddeps for"));
658 std::string hostArch
= _config
->Find("APT::Get::Host-Architecture");
659 if (hostArch
.empty() == false)
661 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
662 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
663 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
664 StripMultiArch
= false;
667 StripMultiArch
= true;
669 std::ostringstream buildDepsPkgFile
;
670 std::vector
<std::pair
<std::string
,std::string
>> pseudoPkgs
;
671 // deal with the build essentials first
673 std::vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
674 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
677 for (; Opts
; Opts
= Opts
->Next
)
679 if (Opts
->Value
.empty() == true)
682 pkgSrcRecords::Parser::BuildDepRec rec
;
683 rec
.Package
= Opts
->Value
;
684 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
686 BuildDeps
.push_back(rec
);
688 std::string
const pseudo
= "builddeps:essentials";
689 std::string
const nativeArch
= _config
->Find("APT::Architecture");
690 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, nativeArch
, BuildDeps
);
691 pseudoPkgs
.emplace_back(pseudo
, nativeArch
);
694 // Read the source list
695 if (Cache
.BuildSourceList() == false)
697 pkgSourceList
*List
= Cache
.GetSourceList();
698 std::string
const pseudoArch
= hostArch
.empty() ? _config
->Find("APT::Architecture") : hostArch
;
700 // FIXME: Avoid volatile sources == cmdline assumption
702 auto const VolatileSources
= List
->GetVolatileFiles();
703 if (VolatileSources
.size() == VolatileCmdL
.size())
705 for (size_t i
= 0; i
< VolatileSources
.size(); ++i
)
707 char const * const Src
= VolatileCmdL
[i
];
708 if (DirectoryExists(Src
))
709 ioprintf(c1out
, _("Note, using directory '%s' to get the build dependencies\n"), Src
);
711 ioprintf(c1out
, _("Note, using file '%s' to get the build dependencies\n"), Src
);
712 std::unique_ptr
<pkgSrcRecords::Parser
> Last(VolatileSources
[i
]->CreateSrcParser());
714 return _error
->Error(_("Unable to find a source package for %s"), Src
);
716 std::string
const pseudo
= std::string("builddeps:") + Src
;
717 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, pseudoArch
,
718 GetBuildDeps(Last
.get(), Src
, StripMultiArch
, hostArch
));
719 pseudoPkgs
.emplace_back(pseudo
, pseudoArch
);
723 return _error
->Error("Implementation error: Volatile sources (%lu) and"
724 "commandline elements (%lu) do not match!", VolatileSources
.size(),
725 VolatileCmdL
.size());
728 if (CmdL
.FileList
[1] != 0)
730 // Create the text record parsers
731 pkgSrcRecords
SrcRecs(*List
);
732 if (_error
->PendingError() == true)
734 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; ++I
)
737 pkgSrcRecords::Parser
* const Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
739 return _error
->Error(_("Unable to find a source package for %s"), *I
);
741 std::string
const pseudo
= std::string("builddeps:") + Src
;
742 WriteBuildDependencyPackage(buildDepsPkgFile
, pseudo
, pseudoArch
,
743 GetBuildDeps(Last
, Src
.c_str(), StripMultiArch
, hostArch
));
744 pseudoPkgs
.emplace_back(pseudo
, pseudoArch
);
748 Cache
.AddIndexFile(new debStringPackageIndex(buildDepsPkgFile
.str()));
750 bool WantLock
= _config
->FindB("APT::Get::Print-URIs", false) == false;
751 if (Cache
.Open(WantLock
) == false)
753 pkgProblemResolver
Fix(Cache
.GetDepCache());
755 APT::PackageVector removeAgain
;
757 pkgDepCache::ActionGroup
group(Cache
);
758 TryToInstall
InstallAction(Cache
, &Fix
, false);
759 for (auto const &pkg
: pseudoPkgs
)
761 pkgCache::PkgIterator
const Pkg
= Cache
->FindPkg(pkg
.first
, pkg
.second
);
764 Cache
->SetCandidateVersion(Pkg
.VersionList());
765 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
766 removeAgain
.push_back(Pkg
);
768 InstallAction
.doAutoInstall();
770 OpTextProgress
Progress(*_config
);
771 bool const resolver_fail
= Fix
.Resolve(true, &Progress
);
772 if (resolver_fail
== false && Cache
->BrokenCount() == 0)
774 if (CheckNothingBroken(Cache
) == false)
777 if (DoAutomaticRemove(Cache
) == false)
780 pkgDepCache::ActionGroup
group(Cache
);
781 for (auto const &pkg
: removeAgain
)
782 Cache
->MarkDelete(pkg
, false, 0, true);
786 if (_error
->PendingError() || InstallPackages(Cache
, false, true) == false)
787 return _error
->Error(_("Failed to process build dependencies"));