]>
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/macros.h>
27 #include <apt-pkg/pkgcache.h>
28 #include <apt-pkg/cacheiterators.h>
29 #include <apt-pkg/strutl.h>
30 #include <apt-pkg/install-progress.h>
41 bool pkgPackageManager :: SigINTStop
= false ;
43 // PM::PackageManager - Constructor /*{{{*/
44 // ---------------------------------------------------------------------
46 pkgPackageManager :: pkgPackageManager ( pkgDepCache
* pCache
) : Cache (* pCache
),
47 List ( NULL
), Res ( Incomplete
), d ( NULL
)
49 FileNames
= new string
[ Cache
. Head (). PackageCount
];
50 Debug
= _config
-> FindB ( "Debug::pkgPackageManager" , false );
51 NoImmConfigure
= ! _config
-> FindB ( "APT::Immediate-Configure" , true );
52 ImmConfigureAll
= _config
-> FindB ( "APT::Immediate-Configure-All" , false );
55 // PM::PackageManager - Destructor /*{{{*/
56 // ---------------------------------------------------------------------
58 pkgPackageManager ::~ pkgPackageManager ()
64 // PM::GetArchives - Queue the archives for download /*{{{*/
65 // ---------------------------------------------------------------------
67 bool pkgPackageManager :: GetArchives ( pkgAcquire
* Owner
, pkgSourceList
* Sources
,
70 if ( CreateOrderList () == false )
74 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
75 List
-> OrderUnpack () : List
-> OrderCritical ();
76 if ( ordering
== false )
77 return _error
-> Error ( "Internal ordering error" );
79 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
81 PkgIterator
Pkg ( Cache
,* I
);
82 FileNames
[ Pkg
-> ID
] = string ();
84 // Skip packages to erase
85 if ( Cache
[ Pkg
]. Delete () == true )
88 // Skip Packages that need configure only.
89 if ( Pkg
. State () == pkgCache :: PkgIterator :: NeedsConfigure
&&
90 Cache
[ Pkg
]. Keep () == true )
93 // Skip already processed packages
94 if ( List
-> IsNow ( Pkg
) == false )
97 new pkgAcqArchive ( Owner
, Sources
, Recs
, Cache
[ Pkg
]. InstVerIter ( Cache
),
104 // PM::FixMissing - Keep all missing packages /*{{{*/
105 // ---------------------------------------------------------------------
106 /* This is called to correct the installation when packages could not
108 bool pkgPackageManager :: FixMissing ()
110 pkgDepCache :: ActionGroup
group ( Cache
);
111 pkgProblemResolver
Resolve (& Cache
);
112 List
-> SetFileList ( FileNames
);
115 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
117 if ( List
-> IsMissing ( I
) == false )
120 // Okay, this file is missing and we need it. Mark it for keep
122 Cache
. MarkKeep ( I
, false , false );
125 // We have to empty the list otherwise it will not have the new changes
132 // Now downgrade everything that is broken
133 return Resolve
. ResolveByKeep () == true && Cache
. BrokenCount () == 0 ;
136 // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
137 // ---------------------------------------------------------------------
138 /* This adds the immediate flag to the pkg and recursively to the
141 void pkgPackageManager :: ImmediateAdd ( PkgIterator I
, bool UseInstallVer
, unsigned const int & Depth
)
147 if ( Cache
[ I
]. InstallVer
== 0 )
149 D
= Cache
[ I
]. InstVerIter ( Cache
). DependsList ();
151 if ( I
-> CurrentVer
== 0 )
153 D
= I
. CurrentVer (). DependsList ();
156 for ( /* nothing */ ; D
. end () == false ; ++ D
)
157 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
159 if (! List
-> IsFlag ( D
. TargetPkg (), pkgOrderList :: Immediate
))
162 clog
<< OutputInDepth ( Depth
) << "ImmediateAdd(): Adding Immediate flag to " << D
. TargetPkg () << " cause of " << D
. DepType () << " " << I
. FullName () << endl
;
163 List
-> Flag ( D
. TargetPkg (), pkgOrderList :: Immediate
);
164 ImmediateAdd ( D
. TargetPkg (), UseInstallVer
, Depth
+ 1 );
170 // PM::CreateOrderList - Create the ordering class /*{{{*/
171 // ---------------------------------------------------------------------
172 /* This populates the ordering list with all the packages that are
174 bool pkgPackageManager :: CreateOrderList ()
180 List
= new pkgOrderList (& Cache
);
182 if ( Debug
&& ImmConfigureAll
)
183 clog
<< "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl
;
185 // Generate the list of affected packages and sort it
186 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
188 // Ignore no-version packages
189 if ( I
-> VersionList
== 0 )
192 // Mark the package and its dependends for immediate configuration
193 if (((( I
-> Flags
& pkgCache :: Flag :: Essential
) == pkgCache :: Flag :: Essential
) &&
194 NoImmConfigure
== false ) || ImmConfigureAll
)
196 if ( Debug
&& ! ImmConfigureAll
)
197 clog
<< "CreateOrderList(): Adding Immediate flag for " << I
. FullName () << endl
;
198 List
-> Flag ( I
, pkgOrderList :: Immediate
);
200 if (! ImmConfigureAll
) {
201 // Look for other install packages to make immediate configurea
202 ImmediateAdd ( I
, true );
204 // And again with the current version.
205 ImmediateAdd ( I
, false );
210 if (( Cache
[ I
]. Keep () == true ||
211 Cache
[ I
]. InstVerIter ( Cache
) == I
. CurrentVer ()) &&
212 I
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
213 ( Cache
[ I
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
&&
214 ( I
. Purge () != false || Cache
[ I
]. Mode
!= pkgDepCache :: ModeDelete
||
215 ( Cache
[ I
]. iFlags
& pkgDepCache :: Purge
) != pkgDepCache :: Purge
))
218 // Append it to the list
225 // PM::DepAlwaysTrue - Returns true if this dep is irrelevant /*{{{*/
226 // ---------------------------------------------------------------------
227 /* The restriction on provides is to eliminate the case when provides
228 are transitioning between valid states [ie exim to smail] */
229 bool pkgPackageManager :: DepAlwaysTrue ( DepIterator D
)
231 if ( D
. TargetPkg ()-> ProvidesList
!= 0 )
234 if (( Cache
[ D
] & pkgDepCache :: DepInstall
) != 0 &&
235 ( Cache
[ D
] & pkgDepCache :: DepNow
) != 0 )
240 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
241 // ---------------------------------------------------------------------
242 /* This looks over the reverses for a conflicts line that needs early
244 bool pkgPackageManager :: CheckRConflicts ( PkgIterator Pkg
, DepIterator D
,
247 for (; D
. end () == false ; ++ D
)
249 if ( D
-> Type
!= pkgCache :: Dep :: Conflicts
&&
250 D
-> Type
!= pkgCache :: Dep :: Obsoletes
)
253 // The package hasn't been changed
254 if ( List
-> IsNow ( Pkg
) == false )
257 // Ignore self conflicts, ignore conflicts from irrelevant versions
258 if ( D
. IsIgnorable ( Pkg
) || D
. ParentVer () != D
. ParentPkg (). CurrentVer ())
261 if ( Cache
. VS (). CheckDep ( Ver
, D
-> CompareOp
, D
. TargetVer ()) == false )
264 if ( EarlyRemove ( D
. ParentPkg (), & D
) == false )
265 return _error
-> Error ( "Reverse conflicts early remove for package ' %s ' failed" ,
266 Pkg
. FullName (). c_str ());
271 // PM::CheckRBreaks - Look for reverse breaks /*{{{*/
272 bool pkgPackageManager :: CheckRBreaks ( PkgIterator
const & Pkg
, DepIterator D
,
273 const char * const Ver
)
275 for (; D
. end () == false ; ++ D
)
277 if ( D
-> Type
!= pkgCache :: Dep :: DpkgBreaks
)
280 PkgIterator
const DP
= D
. ParentPkg ();
281 if ( Cache
[ DP
]. Delete () == false )
284 // Ignore self conflicts, ignore conflicts from irrelevant versions
285 if ( D
. IsIgnorable ( Pkg
) || D
. ParentVer () != DP
. CurrentVer ())
288 if ( Cache
. VS (). CheckDep ( Ver
, D
-> CompareOp
, D
. TargetVer ()) == false )
291 // no earlyremove() here as user has already agreed to the permanent removal
292 if ( SmartRemove ( DP
) == false )
293 return _error
-> Error ( "Internal Error, Could not early remove %s ( %d )" , DP
. FullName (). c_str (), 4 );
298 // PM::ConfigureAll - Run the all out configuration /*{{{*/
299 // ---------------------------------------------------------------------
300 /* This configures every package. It is assumed they are all unpacked and
301 that the final configuration is valid. This is also used to catch packages
302 that have not been configured when using ImmConfigureAll */
303 bool pkgPackageManager :: ConfigureAll ()
305 pkgOrderList
OList (& Cache
);
307 // Populate the order list
308 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
309 if ( List
-> IsFlag ( pkgCache :: PkgIterator ( Cache
,* I
),
310 pkgOrderList :: UnPacked
) == true )
313 if ( OList
. OrderConfigure () == false )
316 std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
317 bool const ConfigurePkgs
= ( conf
== "all" );
319 // Perform the configuring
320 for ( pkgOrderList :: iterator I
= OList
. begin (); I
!= OList
. end (); ++ I
)
322 PkgIterator
Pkg ( Cache
,* I
);
324 /* Check if the package has been configured, this can happen if SmartConfigure
326 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
)) continue ;
328 if ( ConfigurePkgs
== true && SmartConfigure ( Pkg
, 0 ) == false ) {
330 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
331 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 1 );
333 _error
-> Error ( "Internal error, packages left unconfigured. %s " , Pkg
. FullName (). c_str ());
337 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
343 // PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
344 // -----------------------------------------------------------------------
345 /* ensures that a loop of the form A depends B, B depends A (and similar)
346 is not leading us down into infinite recursion segfault land */
347 bool pkgPackageManager :: NonLoopingSmart ( SmartAction
const action
, pkgCache :: PkgIterator
& Pkg
,
348 pkgCache :: PkgIterator DepPkg
, int const Depth
, bool const PkgLoop
,
349 bool * const Bad
, bool * const Changed
)
351 if ( PkgLoop
== false )
352 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
353 bool success
= false ;
356 case UNPACK_IMMEDIATE
: success
= SmartUnPack ( DepPkg
, true , Depth
+ 1 ); break ;
357 case UNPACK
: success
= SmartUnPack ( DepPkg
, false , Depth
+ 1 ); break ;
358 case CONFIGURE
: success
= SmartConfigure ( DepPkg
, Depth
+ 1 ); break ;
360 if ( PkgLoop
== false )
361 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
363 if ( success
== false )
368 if ( Changed
!= NULL
&& List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
373 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
374 // ---------------------------------------------------------------------
375 /* This function tries to put the system in a state where Pkg can be configured.
376 This involves checking each of Pkg's dependencies and unpacking and
377 configuring packages where needed. */
378 bool pkgPackageManager :: SmartConfigure ( PkgIterator Pkg
, int const Depth
)
380 // If this is true, only check and correct and dependencies without the Loop flag
381 bool const PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
384 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
385 clog
<< OutputInDepth ( Depth
) << "SmartConfigure " << Pkg
. FullName () << " (" << InstallVer
. VerStr () << ")" ;
387 clog
<< " (Only Correct Dependencies)" ;
391 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
393 /* Because of the ordered list, most dependencies should be unpacked,
394 however if there is a loop (A depends on B, B depends on A) this will not
395 be the case, so check for dependencies before configuring. */
396 bool Bad
= false , Changed
= false ;
397 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
399 std :: list
< DepIterator
> needConfigure
;
402 // Check each dependency and see if anything needs to be done
403 // so that it can be configured
405 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
407 // Compute a single dependency element (glob or)
408 pkgCache :: DepIterator Start
, End
;
411 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
415 // the first pass checks if we its all good, i.e. if we have
416 // to do anything at all
417 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
419 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
421 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
423 VerIterator
Ver ( Cache
,* I
);
424 PkgIterator DepPkg
= Ver
. ParentPkg ();
426 // Check if the current version of the package is available and will satisfy this dependency
427 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
428 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
429 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
430 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
436 // Check if the version that is going to be installed will satisfy the dependency
437 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
443 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
444 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
447 std :: clog
<< ", but it isn't unpacked yet" ;
449 std :: clog
<< std :: endl
;
453 if ( Cur
== End
|| Bad
== false )
457 // this dependency is in a good state, so we can stop
461 std :: clog
<< OutputInDepth ( Depth
) << "Found ok dep " << Start
. TargetPkg () << std :: endl
;
465 // Check for dependencies that have not been unpacked,
466 // probably due to loops.
467 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
469 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
471 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
473 VerIterator
Ver ( Cache
,* I
);
474 PkgIterator DepPkg
= Ver
. ParentPkg ();
476 // Check if the current version of the package is available and will satisfy this dependency
477 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
478 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
479 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
480 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
483 // Check if the version that is going to be installed will satisfy the dependency
484 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
490 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
491 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
494 std :: clog
<< ", but it isn't unpacked yet" ;
496 std :: clog
<< std :: endl
;
501 clog
<< OutputInDepth ( Depth
) << "Unpacking " << DepPkg
. FullName () << " to avoid loop " << Cur
<< endl
;
502 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
505 // at this point we either unpacked a Dep or we are in a loop,
506 // no need to unpack a second one
510 if ( Cur
== End
|| Bad
== false )
517 needConfigure
. push_back ( Start
);
520 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (1) for %s , aborting" , Pkg
. FullName (). c_str ());
521 } while ( Changed
== true );
523 // now go over anything that needs configuring
524 Bad
= false , Changed
= false , i
= 0 ;
528 for ( std :: list
< DepIterator
>:: const_iterator D
= needConfigure
. begin (); D
!= needConfigure
. end (); ++ D
)
530 // Compute a single dependency element (glob or) without modifying D
531 pkgCache :: DepIterator Start
, End
;
533 pkgCache :: DepIterator Discard
= * D
;
534 Discard
. GlobOr ( Start
, End
);
537 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
541 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
542 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
544 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
546 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
548 VerIterator
Ver ( Cache
,* I
);
549 PkgIterator DepPkg
= Ver
. ParentPkg ();
551 // Check if the version that is going to be installed will satisfy the dependency
552 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
555 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
557 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
559 // This dependency has already been dealt with by another SmartConfigure on Pkg
564 std :: clog
<< OutputInDepth ( Depth
) << "Configure already unpacked " << DepPkg
<< std :: endl
;
565 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
570 else if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
576 if ( Cur
== End
|| Bad
== false )
581 if ( Bad
== true && Changed
== false && Debug
== true )
582 std :: clog
<< OutputInDepth ( Depth
) << "Could not satisfy " << * D
<< std :: endl
;
585 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (2) for %s , aborting" , Pkg
. FullName (). c_str ());
586 } while ( Changed
== true );
589 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
591 // Check for reverse conflicts.
592 if ( CheckRBreaks ( Pkg
, Pkg
. RevDependsList (), instVer
. VerStr ()) == false )
595 for ( PrvIterator P
= instVer
. ProvidesList (); P
. end () == false ; ++ P
)
596 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
597 CheckRBreaks ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
599 if ( PkgLoop
) return true ;
601 static std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
602 static bool const ConfigurePkgs
= ( conf
== "all" || conf
== "smart" );
604 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
605 return _error
-> Error ( "Internal configure error on ' %s '." , Pkg
. FullName (). c_str ());
607 if ( ConfigurePkgs
== true && Configure ( Pkg
) == false )
610 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
612 if (( Cache
[ Pkg
]. InstVerIter ( Cache
)-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
613 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
614 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
616 if ( Pkg
== P
|| List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
617 List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == false ||
618 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
619 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
621 if ( SmartConfigure ( P
, ( Depth
+ 1 )) == false )
626 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) == false )
627 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
632 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
633 // ---------------------------------------------------------------------
634 /* This is called to deal with conflicts arising from unpacking */
635 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
)
637 return EarlyRemove ( Pkg
, NULL
);
639 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
, DepIterator
const * const Dep
)
641 if ( List
-> IsNow ( Pkg
) == false )
644 // Already removed it
645 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
648 // Woops, it will not be re-installed!
649 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: InList
) == false )
652 // these breaks on M-A:same packages can be dealt with. They 'loop' by design
653 if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
&& Dep
-> IsMultiArchImplicit () == true )
656 // Essential packages get special treatment
657 bool IsEssential
= false ;
658 if (( Pkg
-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
659 ( Pkg
-> Flags
& pkgCache :: Flag :: Important
) != 0 )
662 /* Check for packages that are the dependents of essential packages and
664 if ( Pkg
-> CurrentVer
!= 0 )
666 for ( pkgCache :: DepIterator D
= Pkg
. RevDependsList (); D
. end () == false &&
667 IsEssential
== false ; ++ D
)
668 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
669 if (( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
670 ( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Important
) != 0 )
674 if ( IsEssential
== true )
676 if ( _config
-> FindB ( "APT::Force-LoopBreak" , false ) == false )
677 return _error
-> Error ( _ ( "This installation run will require temporarily "
678 "removing the essential package %s due to a "
679 "Conflicts/Pre-Depends loop. This is often bad, "
680 "but if you really want to do it, activate the "
681 "APT::Force-LoopBreak option." ), Pkg
. FullName (). c_str ());
683 // dpkg will auto-deconfigure it, no need for the big remove hammer
684 else if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
)
687 bool Res
= SmartRemove ( Pkg
);
688 if ( Cache
[ Pkg
]. Delete () == false )
689 List
-> Flag ( Pkg
, pkgOrderList :: Removed
, pkgOrderList :: States
);
694 // PM::SmartRemove - Removal Helper /*{{{*/
695 // ---------------------------------------------------------------------
697 bool pkgPackageManager :: SmartRemove ( PkgIterator Pkg
)
699 if ( List
-> IsNow ( Pkg
) == false )
702 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
704 return Remove ( Pkg
,( Cache
[ Pkg
]. iFlags
& pkgDepCache :: Purge
) == pkgDepCache :: Purge
);
707 // PM::SmartUnPack - Install helper /*{{{*/
708 // ---------------------------------------------------------------------
709 /* This puts the system in a state where it can Unpack Pkg, if Pkg is already
710 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
711 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
)
713 return SmartUnPack ( Pkg
, true , 0 );
715 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
, bool const Immediate
, int const Depth
)
717 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
720 clog
<< OutputInDepth ( Depth
) << "SmartUnPack " << Pkg
. FullName ();
721 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
722 if ( Pkg
. CurrentVer () == 0 )
723 clog
<< " (install version " << InstallVer
. VerStr () << ")" ;
725 clog
<< " (replace version " << Pkg
. CurrentVer (). VerStr () << " with " << InstallVer
. VerStr () << ")" ;
727 clog
<< " (Only Perform PreUnpack Checks)" ;
729 clog
<< " immediately" ;
733 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
735 /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
736 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
737 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
738 complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
739 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
740 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
741 bool SomethingBad
= false , Changed
= false ;
742 bool couldBeTemporaryRemoved
= Depth
!= 0 && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == false ;
743 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
748 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
750 // Compute a single dependency element (glob or)
751 pkgCache :: DepIterator Start
, End
;
754 if ( End
-> Type
== pkgCache :: Dep :: PreDepends
)
758 clog
<< OutputInDepth ( Depth
) << "PreDepends order for " << Pkg
. FullName () << std :: endl
;
760 // Look for easy targets: packages that are already okay
761 for ( DepIterator Cur
= Start
; Bad
== true ; ++ Cur
)
763 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
764 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
766 VerIterator
Ver ( Cache
,* I
);
767 PkgIterator Pkg
= Ver
. ParentPkg ();
769 // See if the current version is ok
770 if ( Pkg
. CurrentVer () == Ver
&& List
-> IsNow ( Pkg
) == true &&
771 Pkg
. State () == PkgIterator :: NeedsNothing
&&
772 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
776 clog
<< OutputInDepth ( Depth
) << "Found ok package " << Pkg
. FullName () << endl
;
784 // Look for something that could be configured.
785 for ( DepIterator Cur
= Start
; Bad
== true && Cur
. end () == false ; ++ Cur
)
787 std :: unique_ptr
< Version
*[]> VList ( Cur
. AllTargets ());
788 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
790 VerIterator
Ver ( Cache
,* I
);
791 PkgIterator DepPkg
= Ver
. ParentPkg ();
793 // Not the install version
794 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
797 if ( Cache
[ DepPkg
]. Keep () == true && DepPkg
. State () == PkgIterator :: NeedsNothing
&&
798 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
801 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
807 // check if it needs unpack or if if configure is enough
808 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
) == false )
810 // two packages pre-depending on each other can't be handled sanely
811 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
813 // this isn't an error as there is potential for something else to satisfy it
814 // (like a provides or an or-group member)
816 clog
<< OutputInDepth ( Depth
) << "Unpack loop detected between " << DepPkg
. FullName () << " and " << Pkg
. FullName () << endl
;
821 clog
<< OutputInDepth ( Depth
) << "Trying to SmartUnpack " << DepPkg
. FullName () << endl
;
822 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
828 clog
<< OutputInDepth ( Depth
) << "Trying to SmartConfigure " << DepPkg
. FullName () << endl
;
829 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
839 else if ( End
-> Type
== pkgCache :: Dep :: Conflicts
||
840 End
-> Type
== pkgCache :: Dep :: Obsoletes
||
841 End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
843 std :: unique_ptr
< Version
*[]> VList ( End
. AllTargets ());
844 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
846 VerIterator
Ver ( Cache
,* I
);
847 PkgIterator ConflictPkg
= Ver
. ParentPkg ();
848 if ( ConflictPkg
. CurrentVer () != Ver
)
851 std :: clog
<< OutputInDepth ( Depth
) << "Ignore not-installed version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
855 if ( List
-> IsNow ( ConflictPkg
) == false )
858 std :: clog
<< OutputInDepth ( Depth
) << "Ignore already dealt-with version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
862 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
865 clog
<< OutputInDepth ( Depth
) << "Ignoring " << End
<< " as " << ConflictPkg
. FullName () << "was temporarily removed" << endl
;
869 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
) && PkgLoop
)
871 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
&& End
. IsMultiArchImplicit () == true )
874 clog
<< OutputInDepth ( Depth
) << "Because dependency is MultiArchImplicit we ignored looping on: " << ConflictPkg
<< endl
;
879 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
880 clog
<< OutputInDepth ( Depth
) << "Because of breaks knot, deconfigure " << ConflictPkg
. FullName () << " temporarily" << endl
;
882 clog
<< OutputInDepth ( Depth
) << "Because of conflict knot, removing " << ConflictPkg
. FullName () << " temporarily" << endl
;
884 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
885 return _error
-> Error ( "Internal Error, Could not early remove %s ( %d )" , ConflictPkg
. FullName (). c_str (), 3 );
890 if ( Cache
[ ConflictPkg
]. Delete () == false )
894 clog
<< OutputInDepth ( Depth
) << "Unpacking " << ConflictPkg
. FullName () << " to avoid " << End
;
896 clog
<< " (Looping)" ;
899 // we would like to avoid temporary removals and all that at best via a simple unpack
900 _error
-> PushToStack ();
901 if ( NonLoopingSmart ( UNPACK
, Pkg
, ConflictPkg
, Depth
, PkgLoop
, NULL
, & Changed
) == false )
903 // but if it fails ignore this failure and look for alternative ways of solving
906 clog
<< OutputInDepth ( Depth
) << "Avoidance unpack of " << ConflictPkg
. FullName () << " failed for " << End
<< " ignoring:" << std :: endl
;
907 _error
-> DumpErrors ( std :: clog
);
909 _error
-> RevertToStack ();
910 // ignorance can only happen if a) one of the offenders is already gone
911 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
914 clog
<< OutputInDepth ( Depth
) << "But " << ConflictPkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
916 else if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
919 clog
<< OutputInDepth ( Depth
) << "But " << Pkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
921 // or b) we can make one go (removal or dpkg auto-deconfigure)
925 clog
<< OutputInDepth ( Depth
) << "So temprorary remove/deconfigure " << ConflictPkg
. FullName () << " to satisfy " << End
<< endl
;
926 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
927 return _error
-> Error ( "Internal Error, Could not early remove %s ( %d )" , ConflictPkg
. FullName (). c_str (), 2 );
931 _error
-> MergeWithStack ();
936 clog
<< OutputInDepth ( Depth
) << "Removing " << ConflictPkg
. FullName () << " now to avoid " << End
<< endl
;
937 // no earlyremove() here as user has already agreed to the permanent removal
938 if ( SmartRemove ( Pkg
) == false )
939 return _error
-> Error ( "Internal Error, Could not early remove %s ( %d )" , ConflictPkg
. FullName (). c_str (), 1 );
945 return _error
-> Error ( "Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s , aborting" , Pkg
. FullName (). c_str ());
946 } while ( Changed
== true );
948 if ( SomethingBad
== true )
949 return _error
-> Error ( "Couldn't configure %s , probably a dependency cycle." , Pkg
. FullName (). c_str ());
951 if ( couldBeTemporaryRemoved
== true && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
954 std :: clog
<< OutputInDepth ( Depth
) << "Prevent unpack as " << Pkg
<< " is currently temporarily removed" << std :: endl
;
958 // Check for reverse conflicts.
959 if ( CheckRConflicts ( Pkg
, Pkg
. RevDependsList (),
960 instVer
. VerStr ()) == false )
963 for ( PrvIterator P
= instVer
. ProvidesList ();
964 P
. end () == false ; ++ P
)
965 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
966 CheckRConflicts ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
971 List
-> Flag ( Pkg
, pkgOrderList :: UnPacked
, pkgOrderList :: States
);
973 if ( Immediate
== true && ( instVer
-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
975 /* Do lockstep M-A:same unpacking in two phases:
976 First unpack all installed architectures, then the not installed.
977 This way we avoid that M-A: enabled packages are installed before
978 their older non-M-A enabled packages are replaced by newer versions */
979 bool const installed
= Pkg
-> CurrentVer
!= 0 ;
980 if ( installed
== true &&
981 ( instVer
!= Pkg
. CurrentVer () ||
982 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
983 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
985 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
986 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
988 if ( P
-> CurrentVer
== 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
989 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
990 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
992 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
995 if ( installed
== false && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
997 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
998 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
1000 if ( P
-> CurrentVer
!= 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
1001 List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
1002 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
1003 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
1005 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
1009 // packages which are already unpacked don't need to be unpacked again
1010 else if (( instVer
!= Pkg
. CurrentVer () ||
1011 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
1012 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
1015 if ( Immediate
== true ) {
1016 // Perform immedate configuration of the package.
1017 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == false )
1018 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
1019 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 2 );
1025 // PM::OrderInstall - Installation ordering routine /*{{{*/
1026 // ---------------------------------------------------------------------
1028 pkgPackageManager :: OrderResult
pkgPackageManager :: OrderInstall ()
1030 if ( CreateOrderList () == false )
1036 clog
<< "Beginning to order" << endl
;
1038 bool const ordering
=
1039 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
1040 List
-> OrderUnpack ( FileNames
) : List
-> OrderCritical ();
1041 if ( ordering
== false )
1043 _error
-> Error ( "Internal ordering error" );
1048 clog
<< "Done ordering" << endl
;
1050 bool DoneSomething
= false ;
1051 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1053 PkgIterator
Pkg ( Cache
,* I
);
1055 if ( List
-> IsNow ( Pkg
) == false )
1058 clog
<< "Skipping already done " << Pkg
. FullName () << endl
;
1062 if ( List
-> IsMissing ( Pkg
) == true )
1065 clog
<< "Sequence completed at " << Pkg
. FullName () << endl
;
1066 if ( DoneSomething
== false )
1068 _error
-> Error ( "Internal Error, ordering was unable to handle the media swap" );
1075 if ( Cache
[ Pkg
]. Keep () == true &&
1076 Pkg
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
1077 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
1079 _error
-> Error ( "Internal Error, trying to manipulate a kept package ( %s )" , Pkg
. FullName (). c_str ());
1083 // Perform a delete or an install
1084 if ( Cache
[ Pkg
]. Delete () == true )
1086 if ( SmartRemove ( Pkg
) == false )
1090 if ( SmartUnPack ( Pkg
, List
-> IsFlag ( Pkg
, pkgOrderList :: Immediate
), 0 ) == false )
1092 DoneSomething
= true ;
1094 if ( ImmConfigureAll
) {
1095 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
1096 "PreUnpack Checks" section */
1097 if (! ConfigureAll ())
1102 // Final run through the configure phase
1103 if ( ConfigureAll () == false )
1107 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1109 if ( List
-> IsFlag (* I
, pkgOrderList :: Configured
) == false )
1111 _error
-> Error ( "Internal error, packages left unconfigured. %s " ,
1112 PkgIterator ( Cache
,* I
). FullName (). c_str ());
1119 // PM::DoInstallPostFork - compat /*{{{*/
1120 // ---------------------------------------------------------------------
1122 pkgPackageManager :: OrderResult
1123 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
1125 APT :: Progress :: PackageManager
* progress
= new
1126 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1127 pkgPackageManager :: OrderResult res
= DoInstallPostFork ( progress
);
1132 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1133 // ---------------------------------------------------------------------
1134 pkgPackageManager :: OrderResult
1135 pkgPackageManager :: DoInstallPostFork ( APT :: Progress :: PackageManager
* progress
)
1137 bool goResult
= Go ( progress
);
1138 if ( goResult
== false )
1144 // PM::DoInstall - Does the installation /*{{{*/
1145 // ---------------------------------------------------------------------
1147 pkgPackageManager :: OrderResult
1148 pkgPackageManager :: DoInstall ( int statusFd
)
1150 APT :: Progress :: PackageManager
* progress
= new
1151 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1152 OrderResult res
= DoInstall ( progress
);
1157 // PM::DoInstall - Does the installation /*{{{*/
1158 // ---------------------------------------------------------------------
1159 /* This uses the filenames in FileNames and the information in the
1160 DepCache to perform the installation of packages.*/
1161 pkgPackageManager :: OrderResult
1162 pkgPackageManager :: DoInstall ( APT :: Progress :: PackageManager
* progress
)
1164 if ( DoInstallPreFork () == Failed
)
1167 return DoInstallPostFork ( progress
);