]>
git.saurik.com Git - apt.git/blob - apt-pkg/packagemanager.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: packagemanager.cc,v 1.30 2003/04/27 03:04:15 doogie Exp $
4 /* ######################################################################
6 Package Manager - Abstacts the package manager
8 More work is needed in the area of transitioning provides, ie exim
9 replacing smail. This can cause interesing side effects.
11 Other cases involving conflicts+replaces should be tested.
13 ##################################################################### */
15 // Include Files /*{{{*/
18 #include <apt-pkg/packagemanager.h>
19 #include <apt-pkg/orderlist.h>
20 #include <apt-pkg/depcache.h>
21 #include <apt-pkg/error.h>
22 #include <apt-pkg/version.h>
23 #include <apt-pkg/acquire-item.h>
24 #include <apt-pkg/algorithms.h>
25 #include <apt-pkg/configuration.h>
26 #include <apt-pkg/sptr.h>
34 bool pkgPackageManager :: SigINTStop
= false ;
36 // PM::PackageManager - Constructor /*{{{*/
37 // ---------------------------------------------------------------------
39 pkgPackageManager :: pkgPackageManager ( pkgDepCache
* pCache
) : Cache (* pCache
),
40 List ( NULL
), Res ( Incomplete
)
42 FileNames
= new string
[ Cache
. Head (). PackageCount
];
43 Debug
= _config
-> FindB ( "Debug::pkgPackageManager" , false );
44 NoImmConfigure
= ! _config
-> FindB ( "APT::Immediate-Configure" , true );
45 ImmConfigureAll
= _config
-> FindB ( "APT::Immediate-Configure-All" , false );
48 // PM::PackageManager - Destructor /*{{{*/
49 // ---------------------------------------------------------------------
51 pkgPackageManager ::~ pkgPackageManager ()
57 // PM::GetArchives - Queue the archives for download /*{{{*/
58 // ---------------------------------------------------------------------
60 bool pkgPackageManager :: GetArchives ( pkgAcquire
* Owner
, pkgSourceList
* Sources
,
63 if ( CreateOrderList () == false )
67 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
68 List
-> OrderUnpack () : List
-> OrderCritical ();
69 if ( ordering
== false )
70 return _error
-> Error ( "Internal ordering error" );
72 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
74 PkgIterator
Pkg ( Cache
,* I
);
75 FileNames
[ Pkg
-> ID
] = string ();
77 // Skip packages to erase
78 if ( Cache
[ Pkg
]. Delete () == true )
81 // Skip Packages that need configure only.
82 if ( Pkg
. State () == pkgCache :: PkgIterator :: NeedsConfigure
&&
83 Cache
[ Pkg
]. Keep () == true )
86 // Skip already processed packages
87 if ( List
-> IsNow ( Pkg
) == false )
90 new pkgAcqArchive ( Owner
, Sources
, Recs
, Cache
[ Pkg
]. InstVerIter ( Cache
),
97 // PM::FixMissing - Keep all missing packages /*{{{*/
98 // ---------------------------------------------------------------------
99 /* This is called to correct the installation when packages could not
101 bool pkgPackageManager :: FixMissing ()
103 pkgDepCache :: ActionGroup
group ( Cache
);
104 pkgProblemResolver
Resolve (& Cache
);
105 List
-> SetFileList ( FileNames
);
108 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
110 if ( List
-> IsMissing ( I
) == false )
113 // Okay, this file is missing and we need it. Mark it for keep
115 Cache
. MarkKeep ( I
, false , false );
118 // We have to empty the list otherwise it will not have the new changes
125 // Now downgrade everything that is broken
126 return Resolve
. ResolveByKeep () == true && Cache
. BrokenCount () == 0 ;
129 // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
130 // ---------------------------------------------------------------------
131 /* This adds the immediate flag to the pkg and recursively to the
134 void pkgPackageManager :: ImmediateAdd ( PkgIterator I
, bool UseInstallVer
, unsigned const int & Depth
)
140 if ( Cache
[ I
]. InstallVer
== 0 )
142 D
= Cache
[ I
]. InstVerIter ( Cache
). DependsList ();
144 if ( I
-> CurrentVer
== 0 )
146 D
= I
. CurrentVer (). DependsList ();
149 for ( /* nothing */ ; D
. end () == false ; ++ D
)
150 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
152 if (! List
-> IsFlag ( D
. TargetPkg (), pkgOrderList :: Immediate
))
155 clog
<< OutputInDepth ( Depth
) << "ImmediateAdd(): Adding Immediate flag to " << D
. TargetPkg () << " cause of " << D
. DepType () << " " << I
. FullName () << endl
;
156 List
-> Flag ( D
. TargetPkg (), pkgOrderList :: Immediate
);
157 ImmediateAdd ( D
. TargetPkg (), UseInstallVer
, Depth
+ 1 );
163 // PM::CreateOrderList - Create the ordering class /*{{{*/
164 // ---------------------------------------------------------------------
165 /* This populates the ordering list with all the packages that are
167 bool pkgPackageManager :: CreateOrderList ()
173 List
= new pkgOrderList (& Cache
);
175 if ( Debug
&& ImmConfigureAll
)
176 clog
<< "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl
;
178 // Generate the list of affected packages and sort it
179 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
181 // Ignore no-version packages
182 if ( I
-> VersionList
== 0 )
185 // Mark the package and its dependends for immediate configuration
186 if (((( I
-> Flags
& pkgCache :: Flag :: Essential
) == pkgCache :: Flag :: Essential
) &&
187 NoImmConfigure
== false ) || ImmConfigureAll
)
189 if ( Debug
&& ! ImmConfigureAll
)
190 clog
<< "CreateOrderList(): Adding Immediate flag for " << I
. FullName () << endl
;
191 List
-> Flag ( I
, pkgOrderList :: Immediate
);
193 if (! ImmConfigureAll
) {
194 // Look for other install packages to make immediate configurea
195 ImmediateAdd ( I
, true );
197 // And again with the current version.
198 ImmediateAdd ( I
, false );
203 if (( Cache
[ I
]. Keep () == true ||
204 Cache
[ I
]. InstVerIter ( Cache
) == I
. CurrentVer ()) &&
205 I
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
206 ( Cache
[ I
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
&&
207 ( I
. Purge () != false || Cache
[ I
]. Mode
!= pkgDepCache :: ModeDelete
||
208 ( Cache
[ I
]. iFlags
& pkgDepCache :: Purge
) != pkgDepCache :: Purge
))
211 // Append it to the list
218 // PM::DepAlwaysTrue - Returns true if this dep is irrelevent /*{{{*/
219 // ---------------------------------------------------------------------
220 /* The restriction on provides is to eliminate the case when provides
221 are transitioning between valid states [ie exim to smail] */
222 bool pkgPackageManager :: DepAlwaysTrue ( DepIterator D
)
224 if ( D
. TargetPkg ()-> ProvidesList
!= 0 )
227 if (( Cache
[ D
] & pkgDepCache :: DepInstall
) != 0 &&
228 ( Cache
[ D
] & pkgDepCache :: DepNow
) != 0 )
233 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
234 // ---------------------------------------------------------------------
235 /* This looks over the reverses for a conflicts line that needs early
237 bool pkgPackageManager :: CheckRConflicts ( PkgIterator Pkg
, DepIterator D
,
240 for (; D
. end () == false ; ++ D
)
242 if ( D
-> Type
!= pkgCache :: Dep :: Conflicts
&&
243 D
-> Type
!= pkgCache :: Dep :: Obsoletes
)
246 // The package hasnt been changed
247 if ( List
-> IsNow ( Pkg
) == false )
250 // Ignore self conflicts, ignore conflicts from irrelevent versions
251 if ( D
. IsIgnorable ( Pkg
) || D
. ParentVer () != D
. ParentPkg (). CurrentVer ())
254 if ( Cache
. VS (). CheckDep ( Ver
, D
-> CompareOp
, D
. TargetVer ()) == false )
257 if ( EarlyRemove ( D
. ParentPkg ()) == false )
258 return _error
-> Error ( "Reverse conflicts early remove for package ' %s ' failed" ,
259 Pkg
. FullName (). c_str ());
264 // PM::ConfigureAll - Run the all out configuration /*{{{*/
265 // ---------------------------------------------------------------------
266 /* This configures every package. It is assumed they are all unpacked and
267 that the final configuration is valid. This is also used to catch packages
268 that have not been configured when using ImmConfigureAll */
269 bool pkgPackageManager :: ConfigureAll ()
271 pkgOrderList
OList (& Cache
);
273 // Populate the order list
274 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
275 if ( List
-> IsFlag ( pkgCache :: PkgIterator ( Cache
,* I
),
276 pkgOrderList :: UnPacked
) == true )
279 if ( OList
. OrderConfigure () == false )
282 std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
283 bool const ConfigurePkgs
= ( conf
== "all" );
285 // Perform the configuring
286 for ( pkgOrderList :: iterator I
= OList
. begin (); I
!= OList
. end (); ++ I
)
288 PkgIterator
Pkg ( Cache
,* I
);
290 /* Check if the package has been configured, this can happen if SmartConfigure
292 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
)) continue ;
294 if ( ConfigurePkgs
== true && SmartConfigure ( Pkg
, 0 ) == false ) {
296 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
297 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 1 );
299 _error
-> Error ( "Internal error, packages left unconfigured. %s " , Pkg
. FullName (). c_str ());
303 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
309 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
310 // ---------------------------------------------------------------------
311 /* This function tries to put the system in a state where Pkg can be configured.
312 This involves checking each of Pkg's dependanies and unpacking and
313 configuring packages where needed.
315 Note on failure: This method can fail, without causing any problems.
316 This can happen when using Immediate-Configure-All, SmartUnPack may call
317 SmartConfigure, it may fail because of a complex dependancy situation, but
318 a error will only be reported if ConfigureAll fails. This is why some of the
319 messages this function reports on failure (return false;) as just warnings
320 only shown when debuging*/
321 bool pkgPackageManager :: SmartConfigure ( PkgIterator Pkg
, int const Depth
)
323 // If this is true, only check and correct and dependencies without the Loop flag
324 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
327 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
328 clog
<< OutputInDepth ( Depth
) << "SmartConfigure " << Pkg
. FullName () << " (" << InstallVer
. VerStr () << ")" ;
330 clog
<< " (Only Correct Dependencies)" ;
334 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
336 /* Because of the ordered list, most dependencies should be unpacked,
337 however if there is a loop (A depends on B, B depends on A) this will not
338 be the case, so check for dependencies before configuring. */
340 for ( DepIterator D
= instVer
. DependsList ();
343 // Compute a single dependency element (glob or)
344 pkgCache :: DepIterator Start
;
345 pkgCache :: DepIterator End
;
348 if ( End
-> Type
== pkgCache :: Dep :: Depends
)
351 // Check for dependanices that have not been unpacked, probably due to loops.
352 while ( End
-> Type
== pkgCache :: Dep :: Depends
) {
354 VerIterator InstallVer
;
355 SPtrArray
< Version
*> VList
= Start
. AllTargets ();
357 // Check through each version of each package that could satisfy this dependancy
358 for ( Version
** I
= VList
; * I
!= 0 ; I
++) {
359 VerIterator
Ver ( Cache
,* I
);
360 DepPkg
= Ver
. ParentPkg ();
361 InstallVer
= VerIterator ( Cache
, Cache
[ DepPkg
]. InstallVer
);
363 // Check if the current version of the package is avalible and will satisfy this dependancy
364 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
365 ! List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) && DepPkg
. State () == PkgIterator :: NeedsNothing
)
371 // Check if the version that is going to be installed will satisfy the dependancy
372 if ( Cache
[ DepPkg
]. InstallVer
== * I
) {
373 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
)) {
374 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
) {
375 // This dependancy has already been dealt with by another SmartConfigure on Pkg
378 } else if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
)) {
379 /* Check for a loop to prevent one forming
380 If A depends on B and B depends on A, SmartConfigure will
381 just hop between them if this is not checked. Dont remove the
382 loop flag after finishing however as loop is already set.
383 This means that there is another SmartConfigure call for this
384 package and it will remove the loop flag */
385 Bad
= ! SmartConfigure ( DepPkg
, Depth
+ 1 );
387 /* Check for a loop to prevent one forming
388 If A depends on B and B depends on A, SmartConfigure will
389 just hop between them if this is not checked */
390 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
391 Bad
= ! SmartConfigure ( DepPkg
, Depth
+ 1 );
392 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
394 // If SmartConfigure was succesfull, Bad is false, so break
396 } else if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
)) {
403 /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */
404 if ( InstallVer
!= 0 && Bad
) {
405 if ( List
-> IsNow ( DepPkg
)) {
407 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
))
410 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" << std :: endl
;
414 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
416 cout
<< OutputInDepth ( Depth
) << "Unpacking " << DepPkg
. FullName () << " to avoid loop" << endl
;
417 SmartUnPack ( DepPkg
, true , Depth
+ 1 );
418 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
424 if ( Bad
&& Debug
&& List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
425 std :: clog
<< OutputInDepth ( Depth
) << "Could not satisfy " << Start
<< std :: endl
;
435 _error
-> Warning ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
439 if ( PkgLoop
) return true ;
441 static std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
442 static bool const ConfigurePkgs
= ( conf
== "all" || conf
== "smart" );
444 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
445 return _error
-> Error ( "Internal configure error on ' %s '." , Pkg
. FullName (). c_str ());
447 if ( ConfigurePkgs
== true && Configure ( Pkg
) == false )
450 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
452 if (( Cache
[ Pkg
]. InstVerIter ( Cache
)-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
453 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
454 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
456 if ( Pkg
== P
|| List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
457 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
458 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
460 SmartConfigure ( P
, ( Depth
+ 1 ));
464 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) == false )
465 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
470 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
471 // ---------------------------------------------------------------------
472 /* This is called to deal with conflicts arising from unpacking */
473 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
)
475 if ( List
-> IsNow ( Pkg
) == false )
478 // Already removed it
479 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
482 // Woops, it will not be re-installed!
483 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: InList
) == false )
486 // Essential packages get special treatment
487 bool IsEssential
= false ;
488 if (( Pkg
-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
489 ( Pkg
-> Flags
& pkgCache :: Flag :: Important
) != 0 )
492 /* Check for packages that are the dependents of essential packages and
494 if ( Pkg
-> CurrentVer
!= 0 )
496 for ( DepIterator D
= Pkg
. RevDependsList (); D
. end () == false &&
497 IsEssential
== false ; ++ D
)
498 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
499 if (( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
500 ( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Important
) != 0 )
504 if ( IsEssential
== true )
506 if ( _config
-> FindB ( "APT::Force-LoopBreak" , false ) == false )
507 return _error
-> Error ( _ ( "This installation run will require temporarily "
508 "removing the essential package %s due to a "
509 "Conflicts/Pre-Depends loop. This is often bad, "
510 "but if you really want to do it, activate the "
511 "APT::Force-LoopBreak option." ), Pkg
. FullName (). c_str ());
514 bool Res
= SmartRemove ( Pkg
);
515 if ( Cache
[ Pkg
]. Delete () == false )
516 List
-> Flag ( Pkg
, pkgOrderList :: Removed
, pkgOrderList :: States
);
521 // PM::SmartRemove - Removal Helper /*{{{*/
522 // ---------------------------------------------------------------------
524 bool pkgPackageManager :: SmartRemove ( PkgIterator Pkg
)
526 if ( List
-> IsNow ( Pkg
) == false )
529 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
531 return Remove ( Pkg
,( Cache
[ Pkg
]. iFlags
& pkgDepCache :: Purge
) == pkgDepCache :: Purge
);
534 // PM::SmartUnPack - Install helper /*{{{*/
535 // ---------------------------------------------------------------------
536 /* This puts the system in a state where it can Unpack Pkg, if Pkg is allready
537 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
538 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
)
540 return SmartUnPack ( Pkg
, true , 0 );
542 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
, bool const Immediate
, int const Depth
)
544 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
547 clog
<< OutputInDepth ( Depth
) << "SmartUnPack " << Pkg
. FullName ();
548 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
549 if ( Pkg
. CurrentVer () == 0 )
550 cout
<< " (install version " << InstallVer
. VerStr () << ")" ;
552 cout
<< " (replace version " << Pkg
. CurrentVer (). VerStr () << " with " << InstallVer
. VerStr () << ")" ;
554 cout
<< " (Only Perform PreUnpack Checks)" ;
558 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
560 /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked.
561 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
562 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
563 complex dependancy structures, trying to configure some packages while breaking the loops can complicate things .
564 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
565 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
566 for ( DepIterator D
= instVer
. DependsList ();
569 // Compute a single dependency element (glob or)
570 pkgCache :: DepIterator Start
;
571 pkgCache :: DepIterator End
;
574 while ( End
-> Type
== pkgCache :: Dep :: PreDepends
)
577 clog
<< OutputInDepth ( Depth
) << "PreDepends order for " << Pkg
. FullName () << std :: endl
;
579 // Look for possible ok targets.
580 SPtrArray
< Version
*> VList
= Start
. AllTargets ();
582 for ( Version
** I
= VList
; * I
!= 0 && Bad
== true ; I
++)
584 VerIterator
Ver ( Cache
,* I
);
585 PkgIterator Pkg
= Ver
. ParentPkg ();
587 // See if the current version is ok
588 if ( Pkg
. CurrentVer () == Ver
&& List
-> IsNow ( Pkg
) == true &&
589 Pkg
. State () == PkgIterator :: NeedsNothing
)
593 clog
<< OutputInDepth ( Depth
) << "Found ok package " << Pkg
. FullName () << endl
;
598 // Look for something that could be configured.
599 for ( Version
** I
= VList
; * I
!= 0 && Bad
== true ; I
++)
601 VerIterator
Ver ( Cache
,* I
);
602 PkgIterator Pkg
= Ver
. ParentPkg ();
604 // Not the install version
605 if ( Cache
[ Pkg
]. InstallVer
!= * I
||
606 ( Cache
[ Pkg
]. Keep () == true && Pkg
. State () == PkgIterator :: NeedsNothing
))
609 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
)) {
614 // check if it needs unpack or if if configure is enough
615 if (! List
-> IsFlag ( Pkg
, pkgOrderList :: UnPacked
))
618 clog
<< OutputInDepth ( Depth
) << "Trying to SmartUnpack " << Pkg
. FullName () << endl
;
619 // SmartUnpack with the ImmediateFlag to ensure its really ready
620 Bad
= ! SmartUnPack ( Pkg
, true , Depth
+ 1 );
623 clog
<< OutputInDepth ( Depth
) << "Trying to SmartConfigure " << Pkg
. FullName () << endl
;
624 Bad
= ! SmartConfigure ( Pkg
, Depth
+ 1 );
628 /* If this or element did not match then continue on to the
629 next or element until a matching element is found */
632 // This triggers if someone make a pre-depends/depend loop.
634 return _error
-> Error ( "Couldn't configure pre-depend %s for %s , "
635 "probably a dependency cycle." ,
636 End
. TargetPkg (). FullName (). c_str (), Pkg
. FullName (). c_str ());
643 if ( End
-> Type
== pkgCache :: Dep :: Conflicts
||
644 End
-> Type
== pkgCache :: Dep :: Obsoletes
)
646 /* Look for conflicts. Two packages that are both in the install
647 state cannot conflict so we don't check.. */
648 SPtrArray
< Version
*> VList
= End
. AllTargets ();
649 for ( Version
** I
= VList
; * I
!= 0 ; I
++)
651 VerIterator
Ver ( Cache
,* I
);
652 PkgIterator ConflictPkg
= Ver
. ParentPkg ();
653 VerIterator
InstallVer ( Cache
, Cache
[ ConflictPkg
]. InstallVer
);
655 // See if the current version is conflicting
656 if ( ConflictPkg
. CurrentVer () == Ver
&& List
-> IsNow ( ConflictPkg
))
658 cout
<< OutputInDepth ( Depth
) << Pkg
. FullName () << " conflicts with " << ConflictPkg
. FullName () << endl
;
659 /* If a loop is not present or has not yet been detected, attempt to unpack packages
660 to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */
661 if (! List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
)) {
662 if ( Cache
[ ConflictPkg
]. Keep () == 0 && Cache
[ ConflictPkg
]. InstallVer
!= 0 ) {
664 cout
<< OutputInDepth ( Depth
) << OutputInDepth ( Depth
) << "Unpacking " << ConflictPkg
. FullName () << " to prevent conflict" << endl
;
665 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
666 SmartUnPack ( ConflictPkg
, false , Depth
+ 1 );
667 // Remove loop to allow it to be used later if needed
668 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
670 if ( EarlyRemove ( ConflictPkg
) == false )
671 return _error
-> Error ( "Internal Error, Could not early remove %s " , ConflictPkg
. FullName (). c_str ());
674 if (! List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
)) {
676 cout
<< OutputInDepth ( Depth
) << "Because of conficts knot, removing " << ConflictPkg
. FullName () << " to conflict violation" << endl
;
677 if ( EarlyRemove ( ConflictPkg
) == false )
678 return _error
-> Error ( "Internal Error, Could not early remove %s " , ConflictPkg
. FullName (). c_str ());
686 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
) {
687 SPtrArray
< Version
*> VList
= End
. AllTargets ();
688 for ( Version
** I
= VList
; * I
!= 0 ; I
++)
690 VerIterator
Ver ( Cache
,* I
);
691 PkgIterator BrokenPkg
= Ver
. ParentPkg ();
692 if ( BrokenPkg
. CurrentVer () != Ver
)
695 std :: clog
<< OutputInDepth ( Depth
) << " Ignore not-installed version " << Ver
. VerStr () << " of " << Pkg
. FullName () << " for " << End
<< std :: endl
;
699 // Check if it needs to be unpacked
700 if ( List
-> IsFlag ( BrokenPkg
, pkgOrderList :: InList
) && Cache
[ BrokenPkg
]. Delete () == false &&
701 List
-> IsNow ( BrokenPkg
)) {
702 if ( List
-> IsFlag ( BrokenPkg
, pkgOrderList :: Loop
) && PkgLoop
) {
703 // This dependancy has already been dealt with by another SmartUnPack on Pkg
706 // Found a break, so see if we can unpack the package to avoid it
707 // but do not set loop if another SmartUnPack already deals with it
708 VerIterator
InstallVer ( Cache
, Cache
[ BrokenPkg
]. InstallVer
);
710 for ( pkgCache :: DepIterator D
= InstallVer
. DependsList (); D
. end () == false ; ++ D
)
712 if ( D
-> Type
!= pkgCache :: Dep :: PreDepends
)
714 SPtrArray
< Version
*> VL
= D
. AllTargets ();
715 for ( Version
** I
= VL
; * I
!= 0 ; ++ I
)
717 VerIterator
V ( Cache
,* I
);
718 PkgIterator P
= V
. ParentPkg ();
719 // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers
720 if ( P
-> CurrentVer
== 0 || P
!= Pkg
|| ( P
. CurrentVer () != V
&& Cache
[ P
]. InstallVer
!= V
))
731 cout
<< OutputInDepth ( Depth
) << " Avoiding " << End
<< " avoided as " << BrokenPkg
. FullName () << " has a pre-depends on " << Pkg
. FullName () << std :: endl
;
738 cout
<< OutputInDepth ( Depth
) << " Unpacking " << BrokenPkg
. FullName () << " to avoid " << End
;
740 cout
<< " (Looping)" ;
743 if ( PkgLoop
== false )
744 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
745 SmartUnPack ( BrokenPkg
, false , Depth
+ 1 );
746 if ( PkgLoop
== false )
747 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
751 // Check if a package needs to be removed
752 if ( Cache
[ BrokenPkg
]. Delete () == true && ! List
-> IsFlag ( BrokenPkg
, pkgOrderList :: Configured
))
755 cout
<< OutputInDepth ( Depth
) << " Removing " << BrokenPkg
. FullName () << " to avoid " << End
<< endl
;
756 SmartRemove ( BrokenPkg
);
763 // Check for reverse conflicts.
764 if ( CheckRConflicts ( Pkg
, Pkg
. RevDependsList (),
765 instVer
. VerStr ()) == false )
768 for ( PrvIterator P
= instVer
. ProvidesList ();
769 P
. end () == false ; ++ P
)
770 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
771 CheckRConflicts ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
776 List
-> Flag ( Pkg
, pkgOrderList :: UnPacked
, pkgOrderList :: States
);
778 if ( Immediate
== true && ( instVer
-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
780 /* Do lockstep M-A:same unpacking in two phases:
781 First unpack all installed architectures, then the not installed.
782 This way we avoid that M-A: enabled packages are installed before
783 their older non-M-A enabled packages are replaced by newer versions */
784 bool const installed
= Pkg
-> CurrentVer
!= 0 ;
785 if ( installed
== true && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
787 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
788 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
790 if ( P
-> CurrentVer
== 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
791 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
792 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
794 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
797 if ( installed
== false && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
799 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
800 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
802 if ( P
-> CurrentVer
!= 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
803 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
804 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
806 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
810 // packages which are already unpacked don't need to be unpacked again
811 else if ( Pkg
. State () != pkgCache :: PkgIterator :: NeedsConfigure
&& Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
814 if ( Immediate
== true ) {
815 // Perform immedate configuration of the package.
816 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == false )
817 _error
-> Warning ( _ ( "Could not perform immediate configuration on ' %s '. "
818 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 2 );
824 // PM::OrderInstall - Installation ordering routine /*{{{*/
825 // ---------------------------------------------------------------------
827 pkgPackageManager :: OrderResult
pkgPackageManager :: OrderInstall ()
829 if ( CreateOrderList () == false )
835 clog
<< "Beginning to order" << endl
;
837 bool const ordering
=
838 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
839 List
-> OrderUnpack ( FileNames
) : List
-> OrderCritical ();
840 if ( ordering
== false )
842 _error
-> Error ( "Internal ordering error" );
847 clog
<< "Done ordering" << endl
;
849 bool DoneSomething
= false ;
850 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
852 PkgIterator
Pkg ( Cache
,* I
);
854 if ( List
-> IsNow ( Pkg
) == false )
856 if (! List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) && ! NoImmConfigure
) {
857 if ( SmartConfigure ( Pkg
, 0 ) == false && Debug
)
858 _error
-> Warning ( "Internal Error, Could not configure %s " , Pkg
. FullName (). c_str ());
859 // FIXME: The above warning message might need changing
862 clog
<< "Skipping already done " << Pkg
. FullName () << endl
;
868 if ( List
-> IsMissing ( Pkg
) == true )
871 clog
<< "Sequence completed at " << Pkg
. FullName () << endl
;
872 if ( DoneSomething
== false )
874 _error
-> Error ( "Internal Error, ordering was unable to handle the media swap" );
881 if ( Cache
[ Pkg
]. Keep () == true &&
882 Pkg
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
883 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
885 _error
-> Error ( "Internal Error, trying to manipulate a kept package ( %s )" , Pkg
. FullName (). c_str ());
889 // Perform a delete or an install
890 if ( Cache
[ Pkg
]. Delete () == true )
892 if ( SmartRemove ( Pkg
) == false )
896 if ( SmartUnPack ( Pkg
, List
-> IsFlag ( Pkg
, pkgOrderList :: Immediate
), 0 ) == false )
898 DoneSomething
= true ;
900 if ( ImmConfigureAll
) {
901 /* ConfigureAll here to pick up and packages left unconfigured becuase they were unpacked in the
902 "PreUnpack Checks" section */
908 // Final run through the configure phase
909 if ( ConfigureAll () == false )
913 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
915 if ( List
-> IsFlag (* I
, pkgOrderList :: Configured
) == false )
917 _error
-> Error ( "Internal error, packages left unconfigured. %s " ,
918 PkgIterator ( Cache
,* I
). FullName (). c_str ());
926 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
927 // ---------------------------------------------------------------------
928 pkgPackageManager :: OrderResult
929 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
932 // FIXME: use SetCloseExec here once it taught about throwing
933 // exceptions instead of doing _exit(100) on failure
934 fcntl ( statusFd
, F_SETFD
, FD_CLOEXEC
);
935 bool goResult
= Go ( statusFd
);
936 if ( goResult
== false )
942 // PM::DoInstall - Does the installation /*{{{*/
943 // ---------------------------------------------------------------------
944 /* This uses the filenames in FileNames and the information in the
945 DepCache to perform the installation of packages.*/
946 pkgPackageManager :: OrderResult
pkgPackageManager :: DoInstall ( int statusFd
)
948 if ( DoInstallPreFork () == Failed
)
951 return DoInstallPostFork ( statusFd
);