]>
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>
27 #include <apt-pkg/macros.h>
28 #include <apt-pkg/pkgcache.h>
29 #include <apt-pkg/cacheiterators.h>
30 #include <apt-pkg/strutl.h>
31 #include <apt-pkg/install-progress.h>
42 bool pkgPackageManager :: SigINTStop
= false ;
44 // PM::PackageManager - Constructor /*{{{*/
45 // ---------------------------------------------------------------------
47 pkgPackageManager :: pkgPackageManager ( pkgDepCache
* pCache
) : Cache (* pCache
),
48 List ( NULL
), Res ( Incomplete
), d ( NULL
)
50 FileNames
= new string
[ Cache
. Head (). PackageCount
];
51 Debug
= _config
-> FindB ( "Debug::pkgPackageManager" , false );
52 NoImmConfigure
= ! _config
-> FindB ( "APT::Immediate-Configure" , true );
53 ImmConfigureAll
= _config
-> FindB ( "APT::Immediate-Configure-All" , false );
56 // PM::PackageManager - Destructor /*{{{*/
57 // ---------------------------------------------------------------------
59 pkgPackageManager ::~ pkgPackageManager ()
65 // PM::GetArchives - Queue the archives for download /*{{{*/
66 // ---------------------------------------------------------------------
68 bool pkgPackageManager :: GetArchives ( pkgAcquire
* Owner
, pkgSourceList
* Sources
,
71 if ( CreateOrderList () == false )
75 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
76 List
-> OrderUnpack () : List
-> OrderCritical ();
77 if ( ordering
== false )
78 return _error
-> Error ( "Internal ordering error" );
80 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
82 PkgIterator
Pkg ( Cache
,* I
);
83 FileNames
[ Pkg
-> ID
] = string ();
85 // Skip packages to erase
86 if ( Cache
[ Pkg
]. Delete () == true )
89 // Skip Packages that need configure only.
90 if ( Pkg
. State () == pkgCache :: PkgIterator :: NeedsConfigure
&&
91 Cache
[ Pkg
]. Keep () == true )
94 // Skip already processed packages
95 if ( List
-> IsNow ( Pkg
) == false )
98 new pkgAcqArchive ( Owner
, Sources
, Recs
, Cache
[ Pkg
]. InstVerIter ( Cache
),
105 // PM::FixMissing - Keep all missing packages /*{{{*/
106 // ---------------------------------------------------------------------
107 /* This is called to correct the installation when packages could not
109 bool pkgPackageManager :: FixMissing ()
111 pkgDepCache :: ActionGroup
group ( Cache
);
112 pkgProblemResolver
Resolve (& Cache
);
113 List
-> SetFileList ( FileNames
);
116 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
118 if ( List
-> IsMissing ( I
) == false )
121 // Okay, this file is missing and we need it. Mark it for keep
123 Cache
. MarkKeep ( I
, false , false );
126 // We have to empty the list otherwise it will not have the new changes
133 // Now downgrade everything that is broken
134 return Resolve
. ResolveByKeep () == true && Cache
. BrokenCount () == 0 ;
137 // PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
138 // ---------------------------------------------------------------------
139 /* This adds the immediate flag to the pkg and recursively to the
142 void pkgPackageManager :: ImmediateAdd ( PkgIterator I
, bool UseInstallVer
, unsigned const int & Depth
)
148 if ( Cache
[ I
]. InstallVer
== 0 )
150 D
= Cache
[ I
]. InstVerIter ( Cache
). DependsList ();
152 if ( I
-> CurrentVer
== 0 )
154 D
= I
. CurrentVer (). DependsList ();
157 for ( /* nothing */ ; D
. end () == false ; ++ D
)
158 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
160 if (! List
-> IsFlag ( D
. TargetPkg (), pkgOrderList :: Immediate
))
163 clog
<< OutputInDepth ( Depth
) << "ImmediateAdd(): Adding Immediate flag to " << D
. TargetPkg () << " cause of " << D
. DepType () << " " << I
. FullName () << endl
;
164 List
-> Flag ( D
. TargetPkg (), pkgOrderList :: Immediate
);
165 ImmediateAdd ( D
. TargetPkg (), UseInstallVer
, Depth
+ 1 );
171 // PM::CreateOrderList - Create the ordering class /*{{{*/
172 // ---------------------------------------------------------------------
173 /* This populates the ordering list with all the packages that are
175 bool pkgPackageManager :: CreateOrderList ()
181 List
= new pkgOrderList (& Cache
);
183 if ( Debug
&& ImmConfigureAll
)
184 clog
<< "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl
;
186 // Generate the list of affected packages and sort it
187 for ( PkgIterator I
= Cache
. PkgBegin (); I
. end () == false ; ++ I
)
189 // Ignore no-version packages
190 if ( I
-> VersionList
== 0 )
193 // Mark the package and its dependends for immediate configuration
194 if (((( I
-> Flags
& pkgCache :: Flag :: Essential
) == pkgCache :: Flag :: Essential
) &&
195 NoImmConfigure
== false ) || ImmConfigureAll
)
197 if ( Debug
&& ! ImmConfigureAll
)
198 clog
<< "CreateOrderList(): Adding Immediate flag for " << I
. FullName () << endl
;
199 List
-> Flag ( I
, pkgOrderList :: Immediate
);
201 if (! ImmConfigureAll
) {
202 // Look for other install packages to make immediate configurea
203 ImmediateAdd ( I
, true );
205 // And again with the current version.
206 ImmediateAdd ( I
, false );
211 if (( Cache
[ I
]. Keep () == true ||
212 Cache
[ I
]. InstVerIter ( Cache
) == I
. CurrentVer ()) &&
213 I
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
214 ( Cache
[ I
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
&&
215 ( I
. Purge () != false || Cache
[ I
]. Mode
!= pkgDepCache :: ModeDelete
||
216 ( Cache
[ I
]. iFlags
& pkgDepCache :: Purge
) != pkgDepCache :: Purge
))
219 // Append it to the list
226 // PM::DepAlwaysTrue - Returns true if this dep is irrelevant /*{{{*/
227 // ---------------------------------------------------------------------
228 /* The restriction on provides is to eliminate the case when provides
229 are transitioning between valid states [ie exim to smail] */
230 bool pkgPackageManager :: DepAlwaysTrue ( DepIterator D
)
232 if ( D
. TargetPkg ()-> ProvidesList
!= 0 )
235 if (( Cache
[ D
] & pkgDepCache :: DepInstall
) != 0 &&
236 ( Cache
[ D
] & pkgDepCache :: DepNow
) != 0 )
241 // PM::CheckRConflicts - Look for reverse conflicts /*{{{*/
242 // ---------------------------------------------------------------------
243 /* This looks over the reverses for a conflicts line that needs early
245 bool pkgPackageManager :: CheckRConflicts ( PkgIterator Pkg
, DepIterator D
,
248 for (; D
. end () == false ; ++ D
)
250 if ( D
-> Type
!= pkgCache :: Dep :: Conflicts
&&
251 D
-> Type
!= pkgCache :: Dep :: Obsoletes
)
254 // The package hasn't been changed
255 if ( List
-> IsNow ( Pkg
) == false )
258 // Ignore self conflicts, ignore conflicts from irrelevant versions
259 if ( D
. IsIgnorable ( Pkg
) || D
. ParentVer () != D
. ParentPkg (). CurrentVer ())
262 if ( Cache
. VS (). CheckDep ( Ver
, D
-> CompareOp
, D
. TargetVer ()) == false )
265 if ( EarlyRemove ( D
. ParentPkg (), & D
) == false )
266 return _error
-> Error ( "Reverse conflicts early remove for package ' %s ' failed" ,
267 Pkg
. FullName (). c_str ());
272 // PM::ConfigureAll - Run the all out configuration /*{{{*/
273 // ---------------------------------------------------------------------
274 /* This configures every package. It is assumed they are all unpacked and
275 that the final configuration is valid. This is also used to catch packages
276 that have not been configured when using ImmConfigureAll */
277 bool pkgPackageManager :: ConfigureAll ()
279 pkgOrderList
OList (& Cache
);
281 // Populate the order list
282 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
283 if ( List
-> IsFlag ( pkgCache :: PkgIterator ( Cache
,* I
),
284 pkgOrderList :: UnPacked
) == true )
287 if ( OList
. OrderConfigure () == false )
290 std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
291 bool const ConfigurePkgs
= ( conf
== "all" );
293 // Perform the configuring
294 for ( pkgOrderList :: iterator I
= OList
. begin (); I
!= OList
. end (); ++ I
)
296 PkgIterator
Pkg ( Cache
,* I
);
298 /* Check if the package has been configured, this can happen if SmartConfigure
300 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
)) continue ;
302 if ( ConfigurePkgs
== true && SmartConfigure ( Pkg
, 0 ) == false ) {
304 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
305 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 1 );
307 _error
-> Error ( "Internal error, packages left unconfigured. %s " , Pkg
. FullName (). c_str ());
311 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
317 // PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
318 // -----------------------------------------------------------------------
319 /* ensures that a loop of the form A depends B, B depends A (and similar)
320 is not leading us down into infinite recursion segfault land */
321 bool pkgPackageManager :: NonLoopingSmart ( SmartAction
const action
, pkgCache :: PkgIterator
& Pkg
,
322 pkgCache :: PkgIterator DepPkg
, int const Depth
, bool const PkgLoop
,
323 bool * const Bad
, bool * const Changed
)
325 if ( PkgLoop
== false )
326 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
327 bool success
= false ;
330 case UNPACK_IMMEDIATE
: success
= SmartUnPack ( DepPkg
, true , Depth
+ 1 ); break ;
331 case UNPACK
: success
= SmartUnPack ( DepPkg
, false , Depth
+ 1 ); break ;
332 case CONFIGURE
: success
= SmartConfigure ( DepPkg
, Depth
+ 1 ); break ;
334 if ( PkgLoop
== false )
335 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
337 if ( success
== false )
342 if ( Changed
!= NULL
&& List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
347 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
348 // ---------------------------------------------------------------------
349 /* This function tries to put the system in a state where Pkg can be configured.
350 This involves checking each of Pkg's dependencies and unpacking and
351 configuring packages where needed. */
352 bool pkgPackageManager :: SmartConfigure ( PkgIterator Pkg
, int const Depth
)
354 // If this is true, only check and correct and dependencies without the Loop flag
355 bool const PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
358 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
359 clog
<< OutputInDepth ( Depth
) << "SmartConfigure " << Pkg
. FullName () << " (" << InstallVer
. VerStr () << ")" ;
361 clog
<< " (Only Correct Dependencies)" ;
365 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
367 /* Because of the ordered list, most dependencies should be unpacked,
368 however if there is a loop (A depends on B, B depends on A) this will not
369 be the case, so check for dependencies before configuring. */
370 bool Bad
= false , Changed
= false ;
371 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
373 std :: list
< DepIterator
> needConfigure
;
376 // Check each dependency and see if anything needs to be done
377 // so that it can be configured
379 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
381 // Compute a single dependency element (glob or)
382 pkgCache :: DepIterator Start
, End
;
385 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
389 // the first pass checks if we its all good, i.e. if we have
390 // to do anything at all
391 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
393 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
395 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
397 VerIterator
Ver ( Cache
,* I
);
398 PkgIterator DepPkg
= Ver
. ParentPkg ();
400 // Check if the current version of the package is available and will satisfy this dependency
401 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
402 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
403 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
404 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
410 // Check if the version that is going to be installed will satisfy the dependency
411 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
417 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
418 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
421 std :: clog
<< ", but it isn't unpacked yet" ;
423 std :: clog
<< std :: endl
;
427 if ( Cur
== End
|| Bad
== false )
431 // this dependency is in a good state, so we can stop
435 std :: clog
<< OutputInDepth ( Depth
) << "Found ok dep " << Start
. TargetPkg () << std :: endl
;
439 // Check for dependencies that have not been unpacked,
440 // probably due to loops.
441 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
443 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
445 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
447 VerIterator
Ver ( Cache
,* I
);
448 PkgIterator DepPkg
= Ver
. ParentPkg ();
450 // Check if the current version of the package is available and will satisfy this dependency
451 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
452 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
453 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
454 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
457 // Check if the version that is going to be installed will satisfy the dependency
458 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
464 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
465 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
468 std :: clog
<< ", but it isn't unpacked yet" ;
470 std :: clog
<< std :: endl
;
475 clog
<< OutputInDepth ( Depth
) << "Unpacking " << DepPkg
. FullName () << " to avoid loop " << Cur
<< endl
;
476 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
479 // at this point we either unpacked a Dep or we are in a loop,
480 // no need to unpack a second one
484 if ( Cur
== End
|| Bad
== false )
491 needConfigure
. push_back ( Start
);
494 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (1) for %s , aborting" , Pkg
. FullName (). c_str ());
495 } while ( Changed
== true );
497 // now go over anything that needs configuring
498 Bad
= false , Changed
= false , i
= 0 ;
502 for ( std :: list
< DepIterator
>:: const_iterator D
= needConfigure
. begin (); D
!= needConfigure
. end (); ++ D
)
504 // Compute a single dependency element (glob or) without modifying D
505 pkgCache :: DepIterator Start
, End
;
507 pkgCache :: DepIterator Discard
= * D
;
508 Discard
. GlobOr ( Start
, End
);
511 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
515 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
516 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
518 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
520 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
522 VerIterator
Ver ( Cache
,* I
);
523 PkgIterator DepPkg
= Ver
. ParentPkg ();
525 // Check if the version that is going to be installed will satisfy the dependency
526 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
529 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
531 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
533 // This dependency has already been dealt with by another SmartConfigure on Pkg
538 std :: clog
<< OutputInDepth ( Depth
) << "Configure already unpacked " << DepPkg
<< std :: endl
;
539 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
544 else if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
550 if ( Cur
== End
|| Bad
== false )
555 if ( Bad
== true && Changed
== false && Debug
== true )
556 std :: clog
<< OutputInDepth ( Depth
) << "Could not satisfy " << * D
<< std :: endl
;
559 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (2) for %s , aborting" , Pkg
. FullName (). c_str ());
560 } while ( Changed
== true );
563 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
565 if ( PkgLoop
) return true ;
567 static std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
568 static bool const ConfigurePkgs
= ( conf
== "all" || conf
== "smart" );
570 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
571 return _error
-> Error ( "Internal configure error on ' %s '." , Pkg
. FullName (). c_str ());
573 if ( ConfigurePkgs
== true && Configure ( Pkg
) == false )
576 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
578 if (( Cache
[ Pkg
]. InstVerIter ( Cache
)-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
579 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
580 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
582 if ( Pkg
== P
|| List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
583 List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == false ||
584 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
585 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
587 if ( SmartConfigure ( P
, ( Depth
+ 1 )) == false )
592 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) == false )
593 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
598 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
599 // ---------------------------------------------------------------------
600 /* This is called to deal with conflicts arising from unpacking */
601 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
)
603 return EarlyRemove ( Pkg
, NULL
);
605 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
, DepIterator
const * const Dep
)
607 if ( List
-> IsNow ( Pkg
) == false )
610 // Already removed it
611 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
614 // Woops, it will not be re-installed!
615 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: InList
) == false )
618 // these breaks on M-A:same packages can be dealt with. They 'loop' by design
619 if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
&& Dep
-> IsMultiArchImplicit () == true )
622 // Essential packages get special treatment
623 bool IsEssential
= false ;
624 if (( Pkg
-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
625 ( Pkg
-> Flags
& pkgCache :: Flag :: Important
) != 0 )
628 /* Check for packages that are the dependents of essential packages and
630 if ( Pkg
-> CurrentVer
!= 0 )
632 for ( pkgCache :: DepIterator D
= Pkg
. RevDependsList (); D
. end () == false &&
633 IsEssential
== false ; ++ D
)
634 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
635 if (( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
636 ( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Important
) != 0 )
640 if ( IsEssential
== true )
642 if ( _config
-> FindB ( "APT::Force-LoopBreak" , false ) == false )
643 return _error
-> Error ( _ ( "This installation run will require temporarily "
644 "removing the essential package %s due to a "
645 "Conflicts/Pre-Depends loop. This is often bad, "
646 "but if you really want to do it, activate the "
647 "APT::Force-LoopBreak option." ), Pkg
. FullName (). c_str ());
649 // dpkg will auto-deconfigure it, no need for the big remove hammer
650 else if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
)
653 bool Res
= SmartRemove ( Pkg
);
654 if ( Cache
[ Pkg
]. Delete () == false )
655 List
-> Flag ( Pkg
, pkgOrderList :: Removed
, pkgOrderList :: States
);
660 // PM::SmartRemove - Removal Helper /*{{{*/
661 // ---------------------------------------------------------------------
663 bool pkgPackageManager :: SmartRemove ( PkgIterator Pkg
)
665 if ( List
-> IsNow ( Pkg
) == false )
668 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
670 return Remove ( Pkg
,( Cache
[ Pkg
]. iFlags
& pkgDepCache :: Purge
) == pkgDepCache :: Purge
);
673 // PM::SmartUnPack - Install helper /*{{{*/
674 // ---------------------------------------------------------------------
675 /* This puts the system in a state where it can Unpack Pkg, if Pkg is already
676 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
677 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
)
679 return SmartUnPack ( Pkg
, true , 0 );
681 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
, bool const Immediate
, int const Depth
)
683 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
686 clog
<< OutputInDepth ( Depth
) << "SmartUnPack " << Pkg
. FullName ();
687 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
688 if ( Pkg
. CurrentVer () == 0 )
689 clog
<< " (install version " << InstallVer
. VerStr () << ")" ;
691 clog
<< " (replace version " << Pkg
. CurrentVer (). VerStr () << " with " << InstallVer
. VerStr () << ")" ;
693 clog
<< " (Only Perform PreUnpack Checks)" ;
695 clog
<< " immediately" ;
699 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
701 /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
702 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
703 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
704 complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
705 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
706 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
707 bool SomethingBad
= false , Changed
= false ;
708 bool couldBeTemporaryRemoved
= Depth
!= 0 && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == false ;
709 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
714 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
716 // Compute a single dependency element (glob or)
717 pkgCache :: DepIterator Start
, End
;
720 if ( End
-> Type
== pkgCache :: Dep :: PreDepends
)
724 clog
<< OutputInDepth ( Depth
) << "PreDepends order for " << Pkg
. FullName () << std :: endl
;
726 // Look for easy targets: packages that are already okay
727 for ( DepIterator Cur
= Start
; Bad
== true ; ++ Cur
)
729 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
730 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
732 VerIterator
Ver ( Cache
,* I
);
733 PkgIterator Pkg
= Ver
. ParentPkg ();
735 // See if the current version is ok
736 if ( Pkg
. CurrentVer () == Ver
&& List
-> IsNow ( Pkg
) == true &&
737 Pkg
. State () == PkgIterator :: NeedsNothing
&&
738 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
742 clog
<< OutputInDepth ( Depth
) << "Found ok package " << Pkg
. FullName () << endl
;
750 // Look for something that could be configured.
751 for ( DepIterator Cur
= Start
; Bad
== true && Cur
. end () == false ; ++ Cur
)
753 std :: unique_ptr
< Version
*[]> VList ( Cur
. AllTargets ());
754 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
756 VerIterator
Ver ( Cache
,* I
);
757 PkgIterator DepPkg
= Ver
. ParentPkg ();
759 // Not the install version
760 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
763 if ( Cache
[ DepPkg
]. Keep () == true && DepPkg
. State () == PkgIterator :: NeedsNothing
&&
764 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
767 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
773 // check if it needs unpack or if if configure is enough
774 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
) == false )
776 // two packages pre-depending on each other can't be handled sanely
777 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
779 // this isn't an error as there is potential for something else to satisfy it
780 // (like a provides or an or-group member)
782 clog
<< OutputInDepth ( Depth
) << "Unpack loop detected between " << DepPkg
. FullName () << " and " << Pkg
. FullName () << endl
;
787 clog
<< OutputInDepth ( Depth
) << "Trying to SmartUnpack " << DepPkg
. FullName () << endl
;
788 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
794 clog
<< OutputInDepth ( Depth
) << "Trying to SmartConfigure " << DepPkg
. FullName () << endl
;
795 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
805 else if ( End
-> Type
== pkgCache :: Dep :: Conflicts
||
806 End
-> Type
== pkgCache :: Dep :: Obsoletes
||
807 End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
809 std :: unique_ptr
< Version
*[]> VList ( End
. AllTargets ());
810 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
812 VerIterator
Ver ( Cache
,* I
);
813 PkgIterator ConflictPkg
= Ver
. ParentPkg ();
814 if ( ConflictPkg
. CurrentVer () != Ver
)
817 std :: clog
<< OutputInDepth ( Depth
) << "Ignore not-installed version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
821 if ( List
-> IsNow ( ConflictPkg
) == false )
824 std :: clog
<< OutputInDepth ( Depth
) << "Ignore already dealt-with version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
828 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
831 clog
<< OutputInDepth ( Depth
) << "Ignoring " << End
<< " as " << ConflictPkg
. FullName () << "was temporarily removed" << endl
;
835 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
) && PkgLoop
)
837 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
&& End
. IsMultiArchImplicit () == true )
840 clog
<< OutputInDepth ( Depth
) << "Because dependency is MultiArchImplicit we ignored looping on: " << ConflictPkg
<< endl
;
845 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
846 clog
<< OutputInDepth ( Depth
) << "Because of breaks knot, deconfigure " << ConflictPkg
. FullName () << " temporarily" << endl
;
848 clog
<< OutputInDepth ( Depth
) << "Because of conflict knot, removing " << ConflictPkg
. FullName () << " temporarily" << endl
;
850 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
851 return _error
-> Error ( "Internal Error, Could not early remove %s (2)" , ConflictPkg
. FullName (). c_str ());
856 if ( Cache
[ ConflictPkg
]. Delete () == false )
860 clog
<< OutputInDepth ( Depth
) << "Unpacking " << ConflictPkg
. FullName () << " to avoid " << End
;
862 clog
<< " (Looping)" ;
865 // we would like to avoid temporary removals and all that at best via a simple unpack
866 _error
-> PushToStack ();
867 if ( NonLoopingSmart ( UNPACK
, Pkg
, ConflictPkg
, Depth
, PkgLoop
, NULL
, & Changed
) == false )
869 // but if it fails ignore this failure and look for alternative ways of solving
872 clog
<< OutputInDepth ( Depth
) << "Avoidance unpack of " << ConflictPkg
. FullName () << " failed for " << End
<< " ignoring:" << std :: endl
;
873 _error
-> DumpErrors ( std :: clog
);
875 _error
-> RevertToStack ();
876 // ignorance can only happen if a) one of the offenders is already gone
877 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
880 clog
<< OutputInDepth ( Depth
) << "But " << ConflictPkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
882 else if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
885 clog
<< OutputInDepth ( Depth
) << "But " << Pkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
887 // or b) we can make one go (removal or dpkg auto-deconfigure)
891 clog
<< OutputInDepth ( Depth
) << "So temprorary remove/deconfigure " << ConflictPkg
. FullName () << " to satisfy " << End
<< endl
;
892 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
893 return _error
-> Error ( "Internal Error, Could not early remove %s (2)" , ConflictPkg
. FullName (). c_str ());
897 _error
-> MergeWithStack ();
902 clog
<< OutputInDepth ( Depth
) << "Removing " << ConflictPkg
. FullName () << " now to avoid " << End
<< endl
;
903 // no earlyremove() here as user has already agreed to the permanent removal
904 if ( SmartRemove ( Pkg
) == false )
905 return _error
-> Error ( "Internal Error, Could not early remove %s (1)" , ConflictPkg
. FullName (). c_str ());
911 return _error
-> Error ( "Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s , aborting" , Pkg
. FullName (). c_str ());
912 } while ( Changed
== true );
914 if ( SomethingBad
== true )
915 return _error
-> Error ( "Couldn't configure %s , probably a dependency cycle." , Pkg
. FullName (). c_str ());
917 if ( couldBeTemporaryRemoved
== true && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
920 std :: clog
<< OutputInDepth ( Depth
) << "Prevent unpack as " << Pkg
<< " is currently temporarily removed" << std :: endl
;
924 // Check for reverse conflicts.
925 if ( CheckRConflicts ( Pkg
, Pkg
. RevDependsList (),
926 instVer
. VerStr ()) == false )
929 for ( PrvIterator P
= instVer
. ProvidesList ();
930 P
. end () == false ; ++ P
)
931 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
932 CheckRConflicts ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
937 List
-> Flag ( Pkg
, pkgOrderList :: UnPacked
, pkgOrderList :: States
);
939 if ( Immediate
== true && ( instVer
-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
941 /* Do lockstep M-A:same unpacking in two phases:
942 First unpack all installed architectures, then the not installed.
943 This way we avoid that M-A: enabled packages are installed before
944 their older non-M-A enabled packages are replaced by newer versions */
945 bool const installed
= Pkg
-> CurrentVer
!= 0 ;
946 if ( installed
== true &&
947 ( instVer
!= Pkg
. CurrentVer () ||
948 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
949 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
951 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
952 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
954 if ( P
-> CurrentVer
== 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
955 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
956 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
958 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
961 if ( installed
== false && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
963 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
964 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
966 if ( P
-> CurrentVer
!= 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
967 List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
968 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
969 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
971 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
975 // packages which are already unpacked don't need to be unpacked again
976 else if (( instVer
!= Pkg
. CurrentVer () ||
977 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
978 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
981 if ( Immediate
== true ) {
982 // Perform immedate configuration of the package.
983 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == false )
984 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
985 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 2 );
991 // PM::OrderInstall - Installation ordering routine /*{{{*/
992 // ---------------------------------------------------------------------
994 pkgPackageManager :: OrderResult
pkgPackageManager :: OrderInstall ()
996 if ( CreateOrderList () == false )
1002 clog
<< "Beginning to order" << endl
;
1004 bool const ordering
=
1005 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
1006 List
-> OrderUnpack ( FileNames
) : List
-> OrderCritical ();
1007 if ( ordering
== false )
1009 _error
-> Error ( "Internal ordering error" );
1014 clog
<< "Done ordering" << endl
;
1016 bool DoneSomething
= false ;
1017 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1019 PkgIterator
Pkg ( Cache
,* I
);
1021 if ( List
-> IsNow ( Pkg
) == false )
1024 clog
<< "Skipping already done " << Pkg
. FullName () << endl
;
1028 if ( List
-> IsMissing ( Pkg
) == true )
1031 clog
<< "Sequence completed at " << Pkg
. FullName () << endl
;
1032 if ( DoneSomething
== false )
1034 _error
-> Error ( "Internal Error, ordering was unable to handle the media swap" );
1041 if ( Cache
[ Pkg
]. Keep () == true &&
1042 Pkg
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
1043 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
1045 _error
-> Error ( "Internal Error, trying to manipulate a kept package ( %s )" , Pkg
. FullName (). c_str ());
1049 // Perform a delete or an install
1050 if ( Cache
[ Pkg
]. Delete () == true )
1052 if ( SmartRemove ( Pkg
) == false )
1056 if ( SmartUnPack ( Pkg
, List
-> IsFlag ( Pkg
, pkgOrderList :: Immediate
), 0 ) == false )
1058 DoneSomething
= true ;
1060 if ( ImmConfigureAll
) {
1061 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
1062 "PreUnpack Checks" section */
1063 if (! ConfigureAll ())
1068 // Final run through the configure phase
1069 if ( ConfigureAll () == false )
1073 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1075 if ( List
-> IsFlag (* I
, pkgOrderList :: Configured
) == false )
1077 _error
-> Error ( "Internal error, packages left unconfigured. %s " ,
1078 PkgIterator ( Cache
,* I
). FullName (). c_str ());
1085 // PM::DoInstallPostFork - compat /*{{{*/
1086 // ---------------------------------------------------------------------
1088 pkgPackageManager :: OrderResult
1089 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
1091 APT :: Progress :: PackageManager
* progress
= new
1092 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1093 pkgPackageManager :: OrderResult res
= DoInstallPostFork ( progress
);
1098 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1099 // ---------------------------------------------------------------------
1100 pkgPackageManager :: OrderResult
1101 pkgPackageManager :: DoInstallPostFork ( APT :: Progress :: PackageManager
* progress
)
1103 bool goResult
= Go ( progress
);
1104 if ( goResult
== false )
1110 // PM::DoInstall - Does the installation /*{{{*/
1111 // ---------------------------------------------------------------------
1113 pkgPackageManager :: OrderResult
1114 pkgPackageManager :: DoInstall ( int statusFd
)
1116 APT :: Progress :: PackageManager
* progress
= new
1117 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1118 OrderResult res
= DoInstall ( progress
);
1123 // PM::DoInstall - Does the installation /*{{{*/
1124 // ---------------------------------------------------------------------
1125 /* This uses the filenames in FileNames and the information in the
1126 DepCache to perform the installation of packages.*/
1127 pkgPackageManager :: OrderResult
1128 pkgPackageManager :: DoInstall ( APT :: Progress :: PackageManager
* progress
)
1130 if ( DoInstallPreFork () == Failed
)
1133 return DoInstallPostFork ( progress
);