]>
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::ConfigureAll - Run the all out configuration /*{{{*/
272 // ---------------------------------------------------------------------
273 /* This configures every package. It is assumed they are all unpacked and
274 that the final configuration is valid. This is also used to catch packages
275 that have not been configured when using ImmConfigureAll */
276 bool pkgPackageManager :: ConfigureAll ()
278 pkgOrderList
OList (& Cache
);
280 // Populate the order list
281 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
282 if ( List
-> IsFlag ( pkgCache :: PkgIterator ( Cache
,* I
),
283 pkgOrderList :: UnPacked
) == true )
286 if ( OList
. OrderConfigure () == false )
289 std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
290 bool const ConfigurePkgs
= ( conf
== "all" );
292 // Perform the configuring
293 for ( pkgOrderList :: iterator I
= OList
. begin (); I
!= OList
. end (); ++ I
)
295 PkgIterator
Pkg ( Cache
,* I
);
297 /* Check if the package has been configured, this can happen if SmartConfigure
299 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
)) continue ;
301 if ( ConfigurePkgs
== true && SmartConfigure ( Pkg
, 0 ) == false ) {
303 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
304 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 1 );
306 _error
-> Error ( "Internal error, packages left unconfigured. %s " , Pkg
. FullName (). c_str ());
310 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
316 // PM::NonLoopingSmart - helper to avoid loops while calling Smart methods /*{{{*/
317 // -----------------------------------------------------------------------
318 /* ensures that a loop of the form A depends B, B depends A (and similar)
319 is not leading us down into infinite recursion segfault land */
320 bool pkgPackageManager :: NonLoopingSmart ( SmartAction
const action
, pkgCache :: PkgIterator
& Pkg
,
321 pkgCache :: PkgIterator DepPkg
, int const Depth
, bool const PkgLoop
,
322 bool * const Bad
, bool * const Changed
)
324 if ( PkgLoop
== false )
325 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
326 bool success
= false ;
329 case UNPACK_IMMEDIATE
: success
= SmartUnPack ( DepPkg
, true , Depth
+ 1 ); break ;
330 case UNPACK
: success
= SmartUnPack ( DepPkg
, false , Depth
+ 1 ); break ;
331 case CONFIGURE
: success
= SmartConfigure ( DepPkg
, Depth
+ 1 ); break ;
333 if ( PkgLoop
== false )
334 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
336 if ( success
== false )
341 if ( Changed
!= NULL
&& List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
346 // PM::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
347 // ---------------------------------------------------------------------
348 /* This function tries to put the system in a state where Pkg can be configured.
349 This involves checking each of Pkg's dependencies and unpacking and
350 configuring packages where needed. */
351 bool pkgPackageManager :: SmartConfigure ( PkgIterator Pkg
, int const Depth
)
353 // If this is true, only check and correct and dependencies without the Loop flag
354 bool const PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
357 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
358 clog
<< OutputInDepth ( Depth
) << "SmartConfigure " << Pkg
. FullName () << " (" << InstallVer
. VerStr () << ")" ;
360 clog
<< " (Only Correct Dependencies)" ;
364 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
366 /* Because of the ordered list, most dependencies should be unpacked,
367 however if there is a loop (A depends on B, B depends on A) this will not
368 be the case, so check for dependencies before configuring. */
369 bool Bad
= false , Changed
= false ;
370 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
372 std :: list
< DepIterator
> needConfigure
;
375 // Check each dependency and see if anything needs to be done
376 // so that it can be configured
378 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
380 // Compute a single dependency element (glob or)
381 pkgCache :: DepIterator Start
, End
;
384 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
388 // the first pass checks if we its all good, i.e. if we have
389 // to do anything at all
390 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
392 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
394 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
396 VerIterator
Ver ( Cache
,* I
);
397 PkgIterator DepPkg
= Ver
. ParentPkg ();
399 // Check if the current version of the package is available and will satisfy this dependency
400 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
401 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
402 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
403 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
409 // Check if the version that is going to be installed will satisfy the dependency
410 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
416 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
417 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
420 std :: clog
<< ", but it isn't unpacked yet" ;
422 std :: clog
<< std :: endl
;
426 if ( Cur
== End
|| Bad
== false )
430 // this dependency is in a good state, so we can stop
434 std :: clog
<< OutputInDepth ( Depth
) << "Found ok dep " << Start
. TargetPkg () << std :: endl
;
438 // Check for dependencies that have not been unpacked,
439 // probably due to loops.
440 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
442 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
444 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
446 VerIterator
Ver ( Cache
,* I
);
447 PkgIterator DepPkg
= Ver
. ParentPkg ();
449 // Check if the current version of the package is available and will satisfy this dependency
450 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
451 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
452 DepPkg
. State () == PkgIterator :: NeedsNothing
&&
453 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
456 // Check if the version that is going to be installed will satisfy the dependency
457 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
463 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" ;
464 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
467 std :: clog
<< ", but it isn't unpacked yet" ;
469 std :: clog
<< std :: endl
;
474 clog
<< OutputInDepth ( Depth
) << "Unpacking " << DepPkg
. FullName () << " to avoid loop " << Cur
<< endl
;
475 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
478 // at this point we either unpacked a Dep or we are in a loop,
479 // no need to unpack a second one
483 if ( Cur
== End
|| Bad
== false )
490 needConfigure
. push_back ( Start
);
493 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (1) for %s , aborting" , Pkg
. FullName (). c_str ());
494 } while ( Changed
== true );
496 // now go over anything that needs configuring
497 Bad
= false , Changed
= false , i
= 0 ;
501 for ( std :: list
< DepIterator
>:: const_iterator D
= needConfigure
. begin (); D
!= needConfigure
. end (); ++ D
)
503 // Compute a single dependency element (glob or) without modifying D
504 pkgCache :: DepIterator Start
, End
;
506 pkgCache :: DepIterator Discard
= * D
;
507 Discard
. GlobOr ( Start
, End
);
510 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
514 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
515 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
517 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
519 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
521 VerIterator
Ver ( Cache
,* I
);
522 PkgIterator DepPkg
= Ver
. ParentPkg ();
524 // Check if the version that is going to be installed will satisfy the dependency
525 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
528 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
530 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
532 // This dependency has already been dealt with by another SmartConfigure on Pkg
537 std :: clog
<< OutputInDepth ( Depth
) << "Configure already unpacked " << DepPkg
<< std :: endl
;
538 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
543 else if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
549 if ( Cur
== End
|| Bad
== false )
554 if ( Bad
== true && Changed
== false && Debug
== true )
555 std :: clog
<< OutputInDepth ( Depth
) << "Could not satisfy " << * D
<< std :: endl
;
558 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (2) for %s , aborting" , Pkg
. FullName (). c_str ());
559 } while ( Changed
== true );
562 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
564 if ( PkgLoop
) return true ;
566 static std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
567 static bool const ConfigurePkgs
= ( conf
== "all" || conf
== "smart" );
569 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
570 return _error
-> Error ( "Internal configure error on ' %s '." , Pkg
. FullName (). c_str ());
572 if ( ConfigurePkgs
== true && Configure ( Pkg
) == false )
575 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
577 if (( Cache
[ Pkg
]. InstVerIter ( Cache
)-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
578 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
579 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
581 if ( Pkg
== P
|| List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
582 List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == false ||
583 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
584 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
586 if ( SmartConfigure ( P
, ( Depth
+ 1 )) == false )
591 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) == false )
592 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
597 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
598 // ---------------------------------------------------------------------
599 /* This is called to deal with conflicts arising from unpacking */
600 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
)
602 return EarlyRemove ( Pkg
, NULL
);
604 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
, DepIterator
const * const Dep
)
606 if ( List
-> IsNow ( Pkg
) == false )
609 // Already removed it
610 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
613 // Woops, it will not be re-installed!
614 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: InList
) == false )
617 // these breaks on M-A:same packages can be dealt with. They 'loop' by design
618 if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
&& Dep
-> IsMultiArchImplicit () == true )
621 // Essential packages get special treatment
622 bool IsEssential
= false ;
623 if (( Pkg
-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
624 ( Pkg
-> Flags
& pkgCache :: Flag :: Important
) != 0 )
627 /* Check for packages that are the dependents of essential packages and
629 if ( Pkg
-> CurrentVer
!= 0 )
631 for ( pkgCache :: DepIterator D
= Pkg
. RevDependsList (); D
. end () == false &&
632 IsEssential
== false ; ++ D
)
633 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
634 if (( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
635 ( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Important
) != 0 )
639 if ( IsEssential
== true )
641 if ( _config
-> FindB ( "APT::Force-LoopBreak" , false ) == false )
642 return _error
-> Error ( _ ( "This installation run will require temporarily "
643 "removing the essential package %s due to a "
644 "Conflicts/Pre-Depends loop. This is often bad, "
645 "but if you really want to do it, activate the "
646 "APT::Force-LoopBreak option." ), Pkg
. FullName (). c_str ());
648 // dpkg will auto-deconfigure it, no need for the big remove hammer
649 else if ( Dep
!= NULL
&& (* Dep
)-> Type
== pkgCache :: Dep :: DpkgBreaks
)
652 bool Res
= SmartRemove ( Pkg
);
653 if ( Cache
[ Pkg
]. Delete () == false )
654 List
-> Flag ( Pkg
, pkgOrderList :: Removed
, pkgOrderList :: States
);
659 // PM::SmartRemove - Removal Helper /*{{{*/
660 // ---------------------------------------------------------------------
662 bool pkgPackageManager :: SmartRemove ( PkgIterator Pkg
)
664 if ( List
-> IsNow ( Pkg
) == false )
667 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
669 return Remove ( Pkg
,( Cache
[ Pkg
]. iFlags
& pkgDepCache :: Purge
) == pkgDepCache :: Purge
);
672 // PM::SmartUnPack - Install helper /*{{{*/
673 // ---------------------------------------------------------------------
674 /* This puts the system in a state where it can Unpack Pkg, if Pkg is already
675 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
676 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
)
678 return SmartUnPack ( Pkg
, true , 0 );
680 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
, bool const Immediate
, int const Depth
)
682 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
685 clog
<< OutputInDepth ( Depth
) << "SmartUnPack " << Pkg
. FullName ();
686 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
687 if ( Pkg
. CurrentVer () == 0 )
688 clog
<< " (install version " << InstallVer
. VerStr () << ")" ;
690 clog
<< " (replace version " << Pkg
. CurrentVer (). VerStr () << " with " << InstallVer
. VerStr () << ")" ;
692 clog
<< " (Only Perform PreUnpack Checks)" ;
694 clog
<< " immediately" ;
698 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
700 /* PreUnpack Checks: This loop checks and attempts to rectify any problems that would prevent the package being unpacked.
701 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
702 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
703 complex dependency structures, trying to configure some packages while breaking the loops can complicate things.
704 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
705 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
706 bool SomethingBad
= false , Changed
= false ;
707 bool couldBeTemporaryRemoved
= Depth
!= 0 && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == false ;
708 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
713 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
715 // Compute a single dependency element (glob or)
716 pkgCache :: DepIterator Start
, End
;
719 if ( End
-> Type
== pkgCache :: Dep :: PreDepends
)
723 clog
<< OutputInDepth ( Depth
) << "PreDepends order for " << Pkg
. FullName () << std :: endl
;
725 // Look for easy targets: packages that are already okay
726 for ( DepIterator Cur
= Start
; Bad
== true ; ++ Cur
)
728 std :: unique_ptr
< Version
*> VList ( Cur
. AllTargets ());
729 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
731 VerIterator
Ver ( Cache
,* I
);
732 PkgIterator Pkg
= Ver
. ParentPkg ();
734 // See if the current version is ok
735 if ( Pkg
. CurrentVer () == Ver
&& List
-> IsNow ( Pkg
) == true &&
736 Pkg
. State () == PkgIterator :: NeedsNothing
&&
737 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
741 clog
<< OutputInDepth ( Depth
) << "Found ok package " << Pkg
. FullName () << endl
;
749 // Look for something that could be configured.
750 for ( DepIterator Cur
= Start
; Bad
== true && Cur
. end () == false ; ++ Cur
)
752 std :: unique_ptr
< Version
*[]> VList ( Cur
. AllTargets ());
753 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
755 VerIterator
Ver ( Cache
,* I
);
756 PkgIterator DepPkg
= Ver
. ParentPkg ();
758 // Not the install version
759 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
762 if ( Cache
[ DepPkg
]. Keep () == true && DepPkg
. State () == PkgIterator :: NeedsNothing
&&
763 ( Cache
[ DepPkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
766 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
772 // check if it needs unpack or if if configure is enough
773 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
) == false )
775 // two packages pre-depending on each other can't be handled sanely
776 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
778 // this isn't an error as there is potential for something else to satisfy it
779 // (like a provides or an or-group member)
781 clog
<< OutputInDepth ( Depth
) << "Unpack loop detected between " << DepPkg
. FullName () << " and " << Pkg
. FullName () << endl
;
786 clog
<< OutputInDepth ( Depth
) << "Trying to SmartUnpack " << DepPkg
. FullName () << endl
;
787 if ( NonLoopingSmart ( UNPACK_IMMEDIATE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
793 clog
<< OutputInDepth ( Depth
) << "Trying to SmartConfigure " << DepPkg
. FullName () << endl
;
794 if ( NonLoopingSmart ( CONFIGURE
, Pkg
, DepPkg
, Depth
, PkgLoop
, & Bad
, & Changed
) == false )
804 else if ( End
-> Type
== pkgCache :: Dep :: Conflicts
||
805 End
-> Type
== pkgCache :: Dep :: Obsoletes
||
806 End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
808 std :: unique_ptr
< Version
*[]> VList ( End
. AllTargets ());
809 for ( Version
** I
= VList
. get (); * I
!= 0 ; ++ I
)
811 VerIterator
Ver ( Cache
,* I
);
812 PkgIterator ConflictPkg
= Ver
. ParentPkg ();
813 if ( ConflictPkg
. CurrentVer () != Ver
)
816 std :: clog
<< OutputInDepth ( Depth
) << "Ignore not-installed version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
820 if ( List
-> IsNow ( ConflictPkg
) == false )
823 std :: clog
<< OutputInDepth ( Depth
) << "Ignore already dealt-with version " << Ver
. VerStr () << " of " << ConflictPkg
. FullName () << " for " << End
<< std :: endl
;
827 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
830 clog
<< OutputInDepth ( Depth
) << "Ignoring " << End
<< " as " << ConflictPkg
. FullName () << "was temporarily removed" << endl
;
834 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
) && PkgLoop
)
836 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
&& End
. IsMultiArchImplicit () == true )
839 clog
<< OutputInDepth ( Depth
) << "Because dependency is MultiArchImplicit we ignored looping on: " << ConflictPkg
<< endl
;
844 if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
845 clog
<< OutputInDepth ( Depth
) << "Because of breaks knot, deconfigure " << ConflictPkg
. FullName () << " temporarily" << endl
;
847 clog
<< OutputInDepth ( Depth
) << "Because of conflict knot, removing " << ConflictPkg
. FullName () << " temporarily" << endl
;
849 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
850 return _error
-> Error ( "Internal Error, Could not early remove %s (2)" , ConflictPkg
. FullName (). c_str ());
855 if ( Cache
[ ConflictPkg
]. Delete () == false )
859 clog
<< OutputInDepth ( Depth
) << "Unpacking " << ConflictPkg
. FullName () << " to avoid " << End
;
861 clog
<< " (Looping)" ;
864 // we would like to avoid temporary removals and all that at best via a simple unpack
865 _error
-> PushToStack ();
866 if ( NonLoopingSmart ( UNPACK
, Pkg
, ConflictPkg
, Depth
, PkgLoop
, NULL
, & Changed
) == false )
868 // but if it fails ignore this failure and look for alternative ways of solving
871 clog
<< OutputInDepth ( Depth
) << "Avoidance unpack of " << ConflictPkg
. FullName () << " failed for " << End
<< " ignoring:" << std :: endl
;
872 _error
-> DumpErrors ( std :: clog
);
874 _error
-> RevertToStack ();
875 // ignorance can only happen if a) one of the offenders is already gone
876 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == true )
879 clog
<< OutputInDepth ( Depth
) << "But " << ConflictPkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
881 else if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
884 clog
<< OutputInDepth ( Depth
) << "But " << Pkg
. FullName () << " was temporarily removed in the meantime to satisfy " << End
<< endl
;
886 // or b) we can make one go (removal or dpkg auto-deconfigure)
890 clog
<< OutputInDepth ( Depth
) << "So temprorary remove/deconfigure " << ConflictPkg
. FullName () << " to satisfy " << End
<< endl
;
891 if ( EarlyRemove ( ConflictPkg
, & End
) == false )
892 return _error
-> Error ( "Internal Error, Could not early remove %s (2)" , ConflictPkg
. FullName (). c_str ());
896 _error
-> MergeWithStack ();
901 clog
<< OutputInDepth ( Depth
) << "Removing " << ConflictPkg
. FullName () << " now to avoid " << End
<< endl
;
902 // no earlyremove() here as user has already agreed to the permanent removal
903 if ( SmartRemove ( Pkg
) == false )
904 return _error
-> Error ( "Internal Error, Could not early remove %s (1)" , ConflictPkg
. FullName (). c_str ());
910 return _error
-> Error ( "Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s , aborting" , Pkg
. FullName (). c_str ());
911 } while ( Changed
== true );
913 if ( SomethingBad
== true )
914 return _error
-> Error ( "Couldn't configure %s , probably a dependency cycle." , Pkg
. FullName (). c_str ());
916 if ( couldBeTemporaryRemoved
== true && List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
919 std :: clog
<< OutputInDepth ( Depth
) << "Prevent unpack as " << Pkg
<< " is currently temporarily removed" << std :: endl
;
923 // Check for reverse conflicts.
924 if ( CheckRConflicts ( Pkg
, Pkg
. RevDependsList (),
925 instVer
. VerStr ()) == false )
928 for ( PrvIterator P
= instVer
. ProvidesList ();
929 P
. end () == false ; ++ P
)
930 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
931 CheckRConflicts ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
936 List
-> Flag ( Pkg
, pkgOrderList :: UnPacked
, pkgOrderList :: States
);
938 if ( Immediate
== true && ( instVer
-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
940 /* Do lockstep M-A:same unpacking in two phases:
941 First unpack all installed architectures, then the not installed.
942 This way we avoid that M-A: enabled packages are installed before
943 their older non-M-A enabled packages are replaced by newer versions */
944 bool const installed
= Pkg
-> CurrentVer
!= 0 ;
945 if ( installed
== true &&
946 ( instVer
!= Pkg
. CurrentVer () ||
947 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
948 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
950 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
951 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
953 if ( P
-> CurrentVer
== 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
954 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
955 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
957 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
960 if ( installed
== false && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
962 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
963 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
965 if ( P
-> CurrentVer
!= 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
966 List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
967 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
968 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
970 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
974 // packages which are already unpacked don't need to be unpacked again
975 else if (( instVer
!= Pkg
. CurrentVer () ||
976 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
977 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
980 if ( Immediate
== true ) {
981 // Perform immedate configuration of the package.
982 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == false )
983 _error
-> Error ( _ ( "Could not perform immediate configuration on ' %s '. "
984 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 2 );
990 // PM::OrderInstall - Installation ordering routine /*{{{*/
991 // ---------------------------------------------------------------------
993 pkgPackageManager :: OrderResult
pkgPackageManager :: OrderInstall ()
995 if ( CreateOrderList () == false )
1001 clog
<< "Beginning to order" << endl
;
1003 bool const ordering
=
1004 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
1005 List
-> OrderUnpack ( FileNames
) : List
-> OrderCritical ();
1006 if ( ordering
== false )
1008 _error
-> Error ( "Internal ordering error" );
1013 clog
<< "Done ordering" << endl
;
1015 bool DoneSomething
= false ;
1016 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1018 PkgIterator
Pkg ( Cache
,* I
);
1020 if ( List
-> IsNow ( Pkg
) == false )
1023 clog
<< "Skipping already done " << Pkg
. FullName () << endl
;
1027 if ( List
-> IsMissing ( Pkg
) == true )
1030 clog
<< "Sequence completed at " << Pkg
. FullName () << endl
;
1031 if ( DoneSomething
== false )
1033 _error
-> Error ( "Internal Error, ordering was unable to handle the media swap" );
1040 if ( Cache
[ Pkg
]. Keep () == true &&
1041 Pkg
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
1042 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
1044 _error
-> Error ( "Internal Error, trying to manipulate a kept package ( %s )" , Pkg
. FullName (). c_str ());
1048 // Perform a delete or an install
1049 if ( Cache
[ Pkg
]. Delete () == true )
1051 if ( SmartRemove ( Pkg
) == false )
1055 if ( SmartUnPack ( Pkg
, List
-> IsFlag ( Pkg
, pkgOrderList :: Immediate
), 0 ) == false )
1057 DoneSomething
= true ;
1059 if ( ImmConfigureAll
) {
1060 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
1061 "PreUnpack Checks" section */
1062 if (! ConfigureAll ())
1067 // Final run through the configure phase
1068 if ( ConfigureAll () == false )
1072 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1074 if ( List
-> IsFlag (* I
, pkgOrderList :: Configured
) == false )
1076 _error
-> Error ( "Internal error, packages left unconfigured. %s " ,
1077 PkgIterator ( Cache
,* I
). FullName (). c_str ());
1084 // PM::DoInstallPostFork - compat /*{{{*/
1085 // ---------------------------------------------------------------------
1087 pkgPackageManager :: OrderResult
1088 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
1090 APT :: Progress :: PackageManager
* progress
= new
1091 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1092 pkgPackageManager :: OrderResult res
= DoInstallPostFork ( progress
);
1097 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1098 // ---------------------------------------------------------------------
1099 pkgPackageManager :: OrderResult
1100 pkgPackageManager :: DoInstallPostFork ( APT :: Progress :: PackageManager
* progress
)
1102 bool goResult
= Go ( progress
);
1103 if ( goResult
== false )
1109 // PM::DoInstall - Does the installation /*{{{*/
1110 // ---------------------------------------------------------------------
1112 pkgPackageManager :: OrderResult
1113 pkgPackageManager :: DoInstall ( int statusFd
)
1115 APT :: Progress :: PackageManager
* progress
= new
1116 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1117 OrderResult res
= DoInstall ( progress
);
1122 // PM::DoInstall - Does the installation /*{{{*/
1123 // ---------------------------------------------------------------------
1124 /* This uses the filenames in FileNames and the information in the
1125 DepCache to perform the installation of packages.*/
1126 pkgPackageManager :: OrderResult
1127 pkgPackageManager :: DoInstall ( APT :: Progress :: PackageManager
* progress
)
1129 if ( DoInstallPreFork () == Failed
)
1132 return DoInstallPostFork ( progress
);