]>
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
)
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 ()) == 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::SmartConfigure - Perform immediate configuration of the pkg /*{{{*/
318 // ---------------------------------------------------------------------
319 /* This function tries to put the system in a state where Pkg can be configured.
320 This involves checking each of Pkg's dependanies and unpacking and
321 configuring packages where needed.
323 Note on failure: This method can fail, without causing any problems.
324 This can happen when using Immediate-Configure-All, SmartUnPack may call
325 SmartConfigure, it may fail because of a complex dependency situation, but
326 a error will only be reported if ConfigureAll fails. This is why some of the
327 messages this function reports on failure (return false;) as just warnings
328 only shown when debuging*/
329 bool pkgPackageManager :: SmartConfigure ( PkgIterator Pkg
, int const Depth
)
331 // If this is true, only check and correct and dependencies without the Loop flag
332 bool const PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
335 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
336 clog
<< OutputInDepth ( Depth
) << "SmartConfigure " << Pkg
. FullName () << " (" << InstallVer
. VerStr () << ")" ;
338 clog
<< " (Only Correct Dependencies)" ;
342 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
344 /* Because of the ordered list, most dependencies should be unpacked,
345 however if there is a loop (A depends on B, B depends on A) this will not
346 be the case, so check for dependencies before configuring. */
347 bool Bad
= false , Changed
= false ;
348 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
350 std :: list
< DepIterator
> needConfigure
;
354 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
356 // Compute a single dependency element (glob or)
357 pkgCache :: DepIterator Start
, End
;
360 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
364 // Check for dependencies that have not been unpacked, probably due to loops.
365 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
367 SPtrArray
< Version
*> VList
= Cur
. AllTargets ();
369 for ( Version
** I
= VList
; * I
!= 0 ; ++ I
)
371 VerIterator
Ver ( Cache
,* I
);
372 PkgIterator DepPkg
= Ver
. ParentPkg ();
374 // Check if the current version of the package is available and will satisfy this dependency
375 if ( DepPkg
. CurrentVer () == Ver
&& List
-> IsNow ( DepPkg
) == true &&
376 List
-> IsFlag ( DepPkg
, pkgOrderList :: Removed
) == false &&
377 DepPkg
. State () == PkgIterator :: NeedsNothing
)
383 // Check if the version that is going to be installed will satisfy the dependency
384 if ( Cache
[ DepPkg
]. InstallVer
!= * I
|| List
-> IsNow ( DepPkg
) == false )
390 std :: clog
<< OutputInDepth ( Depth
) << "Package " << Pkg
<< " loops in SmartConfigure" << std :: endl
;
397 clog
<< OutputInDepth ( Depth
) << "Unpacking " << DepPkg
. FullName () << " to avoid loop " << Cur
<< endl
;
398 if ( PkgLoop
== false )
399 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
400 if ( SmartUnPack ( DepPkg
, true , Depth
+ 1 ) == true )
403 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
406 if ( PkgLoop
== false )
407 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
413 if ( Cur
== End
|| Bad
== false )
420 needConfigure
. push_back ( Start
);
423 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (1) for %s , aborting" , Pkg
. FullName (). c_str ());
424 } while ( Changed
== true );
426 Bad
= false , Changed
= false , i
= 0 ;
430 for ( std :: list
< DepIterator
>:: const_iterator D
= needConfigure
. begin (); D
!= needConfigure
. end (); ++ D
)
432 // Compute a single dependency element (glob or) without modifying D
433 pkgCache :: DepIterator Start
, End
;
435 pkgCache :: DepIterator Discard
= * D
;
436 Discard
. GlobOr ( Start
, End
);
439 if ( End
-> Type
!= pkgCache :: Dep :: Depends
)
443 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
444 for ( DepIterator Cur
= Start
; true ; ++ Cur
)
446 SPtrArray
< Version
*> VList
= Cur
. AllTargets ();
448 for ( Version
** I
= VList
; * I
!= 0 ; ++ I
)
450 VerIterator
Ver ( Cache
,* I
);
451 PkgIterator DepPkg
= Ver
. ParentPkg ();
453 // Check if the version that is going to be installed will satisfy the dependency
454 if ( Cache
[ DepPkg
]. InstallVer
!= * I
)
457 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: UnPacked
))
459 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) && PkgLoop
)
461 // This dependency has already been dealt with by another SmartConfigure on Pkg
465 /* Check for a loop to prevent one forming
466 If A depends on B and B depends on A, SmartConfigure will
467 just hop between them if this is not checked. Dont remove the
468 loop flag after finishing however as loop is already set.
469 This means that there is another SmartConfigure call for this
470 package and it will remove the loop flag */
471 if ( PkgLoop
== false )
472 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
473 if ( SmartConfigure ( DepPkg
, Depth
+ 1 ) == true )
476 if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Loop
) == false )
479 if ( PkgLoop
== false )
480 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
481 // If SmartConfigure was succesfull, Bad is false, so break
485 else if ( List
-> IsFlag ( DepPkg
, pkgOrderList :: Configured
))
491 if ( Cur
== End
|| Bad
== false )
496 if ( Bad
== true && Changed
== false && Debug
== true )
497 std :: clog
<< OutputInDepth ( Depth
) << "Could not satisfy " << * D
<< std :: endl
;
500 return _error
-> Error ( "Internal error: MaxLoopCount reached in SmartUnPack (2) for %s , aborting" , Pkg
. FullName (). c_str ());
501 } while ( Changed
== true );
505 _error
-> Warning ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
509 if ( PkgLoop
) return true ;
511 static std :: string
const conf
= _config
-> Find ( "PackageManager::Configure" , "all" );
512 static bool const ConfigurePkgs
= ( conf
== "all" || conf
== "smart" );
514 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
515 return _error
-> Error ( "Internal configure error on ' %s '." , Pkg
. FullName (). c_str ());
517 if ( ConfigurePkgs
== true && Configure ( Pkg
) == false )
520 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
522 if (( Cache
[ Pkg
]. InstVerIter ( Cache
)-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
523 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
524 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
526 if ( Pkg
== P
|| List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
527 List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == false ||
528 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
529 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
531 SmartConfigure ( P
, ( Depth
+ 1 ));
535 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
) == false )
536 return _error
-> Error ( _ ( "Could not configure ' %s '. " ), Pkg
. FullName (). c_str ());
541 // PM::EarlyRemove - Perform removal of packages before their time /*{{{*/
542 // ---------------------------------------------------------------------
543 /* This is called to deal with conflicts arising from unpacking */
544 bool pkgPackageManager :: EarlyRemove ( PkgIterator Pkg
)
546 if ( List
-> IsNow ( Pkg
) == false )
549 // Already removed it
550 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Removed
) == true )
553 // Woops, it will not be re-installed!
554 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: InList
) == false )
557 // Essential packages get special treatment
558 bool IsEssential
= false ;
559 if (( Pkg
-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
560 ( Pkg
-> Flags
& pkgCache :: Flag :: Important
) != 0 )
563 /* Check for packages that are the dependents of essential packages and
565 if ( Pkg
-> CurrentVer
!= 0 )
567 for ( DepIterator D
= Pkg
. RevDependsList (); D
. end () == false &&
568 IsEssential
== false ; ++ D
)
569 if ( D
-> Type
== pkgCache :: Dep :: Depends
|| D
-> Type
== pkgCache :: Dep :: PreDepends
)
570 if (( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Essential
) != 0 ||
571 ( D
. ParentPkg ()-> Flags
& pkgCache :: Flag :: Important
) != 0 )
575 if ( IsEssential
== true )
577 if ( _config
-> FindB ( "APT::Force-LoopBreak" , false ) == false )
578 return _error
-> Error ( _ ( "This installation run will require temporarily "
579 "removing the essential package %s due to a "
580 "Conflicts/Pre-Depends loop. This is often bad, "
581 "but if you really want to do it, activate the "
582 "APT::Force-LoopBreak option." ), Pkg
. FullName (). c_str ());
585 bool Res
= SmartRemove ( Pkg
);
586 if ( Cache
[ Pkg
]. Delete () == false )
587 List
-> Flag ( Pkg
, pkgOrderList :: Removed
, pkgOrderList :: States
);
592 // PM::SmartRemove - Removal Helper /*{{{*/
593 // ---------------------------------------------------------------------
595 bool pkgPackageManager :: SmartRemove ( PkgIterator Pkg
)
597 if ( List
-> IsNow ( Pkg
) == false )
600 List
-> Flag ( Pkg
, pkgOrderList :: Configured
, pkgOrderList :: States
);
602 return Remove ( Pkg
,( Cache
[ Pkg
]. iFlags
& pkgDepCache :: Purge
) == pkgDepCache :: Purge
);
605 // PM::SmartUnPack - Install helper /*{{{*/
606 // ---------------------------------------------------------------------
607 /* This puts the system in a state where it can Unpack Pkg, if Pkg is already
608 unpacked, or when it has been unpacked, if Immediate==true it configures it. */
609 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
)
611 return SmartUnPack ( Pkg
, true , 0 );
613 bool pkgPackageManager :: SmartUnPack ( PkgIterator Pkg
, bool const Immediate
, int const Depth
)
615 bool PkgLoop
= List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
);
618 clog
<< OutputInDepth ( Depth
) << "SmartUnPack " << Pkg
. FullName ();
619 VerIterator InstallVer
= VerIterator ( Cache
, Cache
[ Pkg
]. InstallVer
);
620 if ( Pkg
. CurrentVer () == 0 )
621 clog
<< " (install version " << InstallVer
. VerStr () << ")" ;
623 clog
<< " (replace version " << Pkg
. CurrentVer (). VerStr () << " with " << InstallVer
. VerStr () << ")" ;
625 clog
<< " (Only Perform PreUnpack Checks)" ;
627 clog
<< " immediately" ;
631 VerIterator
const instVer
= Cache
[ Pkg
]. InstVerIter ( Cache
);
633 /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked.
634 It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should
635 avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with
636 complex dependency structures, trying to configure some packages while breaking the loops can complicate things .
637 This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured),
638 or by the ConfigureAll call at the end of the for loop in OrderInstall. */
639 bool Changed
= false ;
640 const unsigned int max_loops
= _config
-> FindI ( "APT::pkgPackageManager::MaxLoopCount" , 5000 );
645 for ( DepIterator D
= instVer
. DependsList (); D
. end () == false ; )
647 // Compute a single dependency element (glob or)
648 pkgCache :: DepIterator Start
, End
;
651 if ( End
-> Type
== pkgCache :: Dep :: PreDepends
)
655 clog
<< OutputInDepth ( Depth
) << "PreDepends order for " << Pkg
. FullName () << std :: endl
;
657 // Look for easy targets: packages that are already okay
658 for ( DepIterator Cur
= Start
; Bad
== true ; ++ Cur
)
660 SPtrArray
< Version
*> VList
= Cur
. AllTargets ();
661 for ( Version
** I
= VList
; * I
!= 0 ; ++ I
)
663 VerIterator
Ver ( Cache
,* I
);
664 PkgIterator Pkg
= Ver
. ParentPkg ();
666 // See if the current version is ok
667 if ( Pkg
. CurrentVer () == Ver
&& List
-> IsNow ( Pkg
) == true &&
668 Pkg
. State () == PkgIterator :: NeedsNothing
)
672 clog
<< OutputInDepth ( Depth
) << "Found ok package " << Pkg
. FullName () << endl
;
680 // Look for something that could be configured.
681 for ( DepIterator Cur
= Start
; Bad
== true && Cur
. end () == false ; ++ Cur
)
683 SPtrArray
< Version
*> VList
= Cur
. AllTargets ();
684 for ( Version
** I
= VList
; * I
!= 0 ; ++ I
)
686 VerIterator
Ver ( Cache
,* I
);
687 PkgIterator Pkg
= Ver
. ParentPkg ();
689 // Not the install version
690 if ( Cache
[ Pkg
]. InstallVer
!= * I
||
691 ( Cache
[ Pkg
]. Keep () == true && Pkg
. State () == PkgIterator :: NeedsNothing
))
694 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Configured
))
700 // check if it needs unpack or if if configure is enough
701 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: UnPacked
) == false )
704 clog
<< OutputInDepth ( Depth
) << "Trying to SmartUnpack " << Pkg
. FullName () << endl
;
705 // SmartUnpack with the ImmediateFlag to ensure its really ready
706 if ( SmartUnPack ( Pkg
, true , Depth
+ 1 ) == true )
709 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
) == false )
717 clog
<< OutputInDepth ( Depth
) << "Trying to SmartConfigure " << Pkg
. FullName () << endl
;
718 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == true )
721 if ( List
-> IsFlag ( Pkg
, pkgOrderList :: Loop
) == false )
732 return _error
-> Error ( "Couldn't configure pre-depend %s for %s , "
733 "probably a dependency cycle." ,
734 End
. TargetPkg (). FullName (). c_str (), Pkg
. FullName (). c_str ());
739 else if ( End
-> Type
== pkgCache :: Dep :: Conflicts
||
740 End
-> Type
== pkgCache :: Dep :: Obsoletes
)
742 /* Look for conflicts. Two packages that are both in the install
743 state cannot conflict so we don't check.. */
744 SPtrArray
< Version
*> VList
= End
. AllTargets ();
745 for ( Version
** I
= VList
; * I
!= 0 ; I
++)
747 VerIterator
Ver ( Cache
,* I
);
748 PkgIterator ConflictPkg
= Ver
. ParentPkg ();
749 VerIterator
InstallVer ( Cache
, Cache
[ ConflictPkg
]. InstallVer
);
751 // See if the current version is conflicting
752 if ( ConflictPkg
. CurrentVer () == Ver
&& List
-> IsNow ( ConflictPkg
))
755 clog
<< OutputInDepth ( Depth
) << Pkg
. FullName () << " conflicts with " << ConflictPkg
. FullName () << endl
;
756 /* If a loop is not present or has not yet been detected, attempt to unpack packages
757 to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */
758 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
) == false )
760 if ( Cache
[ ConflictPkg
]. Keep () == 0 && Cache
[ ConflictPkg
]. InstallVer
!= 0 )
763 clog
<< OutputInDepth ( Depth
) << OutputInDepth ( Depth
) << "Unpacking " << ConflictPkg
. FullName () << " to prevent conflict" << endl
;
764 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
765 if ( SmartUnPack ( ConflictPkg
, false , Depth
+ 1 ) == true )
766 if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Loop
) == false )
768 // Remove loop to allow it to be used later if needed
769 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
771 else if ( EarlyRemove ( ConflictPkg
) == false )
772 return _error
-> Error ( "Internal Error, Could not early remove %s (1)" , ConflictPkg
. FullName (). c_str ());
774 else if ( List
-> IsFlag ( ConflictPkg
, pkgOrderList :: Removed
) == false )
777 clog
<< OutputInDepth ( Depth
) << "Because of conficts knot, removing " << ConflictPkg
. FullName () << " to conflict violation" << endl
;
778 if ( EarlyRemove ( ConflictPkg
) == false )
779 return _error
-> Error ( "Internal Error, Could not early remove %s (2)" , ConflictPkg
. FullName (). c_str ());
784 else if ( End
-> Type
== pkgCache :: Dep :: DpkgBreaks
)
786 SPtrArray
< Version
*> VList
= End
. AllTargets ();
787 for ( Version
** I
= VList
; * I
!= 0 ; ++ I
)
789 VerIterator
Ver ( Cache
,* I
);
790 PkgIterator BrokenPkg
= Ver
. ParentPkg ();
791 if ( BrokenPkg
. CurrentVer () != Ver
)
794 std :: clog
<< OutputInDepth ( Depth
) << " Ignore not-installed version " << Ver
. VerStr () << " of " << Pkg
. FullName () << " for " << End
<< std :: endl
;
798 // Check if it needs to be unpacked
799 if ( List
-> IsFlag ( BrokenPkg
, pkgOrderList :: InList
) && Cache
[ BrokenPkg
]. Delete () == false &&
800 List
-> IsNow ( BrokenPkg
))
802 if ( List
-> IsFlag ( BrokenPkg
, pkgOrderList :: Loop
) && PkgLoop
)
804 // This dependency has already been dealt with by another SmartUnPack on Pkg
809 // Found a break, so see if we can unpack the package to avoid it
810 // but do not set loop if another SmartUnPack already deals with it
811 // Also, avoid it if the package we would unpack pre-depends on this one
812 VerIterator
InstallVer ( Cache
, Cache
[ BrokenPkg
]. InstallVer
);
814 for ( pkgCache :: DepIterator D
= InstallVer
. DependsList (); D
. end () == false ; ++ D
)
816 if ( D
-> Type
!= pkgCache :: Dep :: PreDepends
)
818 SPtrArray
< Version
*> VL
= D
. AllTargets ();
819 for ( Version
** I
= VL
; * I
!= 0 ; ++ I
)
821 VerIterator
V ( Cache
,* I
);
822 PkgIterator P
= V
. ParentPkg ();
823 // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers
824 if ( P
!= Pkg
|| ( P
. CurrentVer () != V
&& Cache
[ P
]. InstallVer
!= V
))
835 clog
<< OutputInDepth ( Depth
) << " Avoiding " << End
<< " avoided as " << BrokenPkg
. FullName () << " has a pre-depends on " << Pkg
. FullName () << std :: endl
;
842 clog
<< OutputInDepth ( Depth
) << " Unpacking " << BrokenPkg
. FullName () << " to avoid " << End
;
844 clog
<< " (Looping)" ;
847 if ( PkgLoop
== false )
848 List
-> Flag ( Pkg
, pkgOrderList :: Loop
);
849 if ( SmartUnPack ( BrokenPkg
, false , Depth
+ 1 ) == true )
851 if ( List
-> IsFlag ( BrokenPkg
, pkgOrderList :: Loop
) == false )
854 if ( PkgLoop
== false )
855 List
-> RmFlag ( Pkg
, pkgOrderList :: Loop
);
859 // Check if a package needs to be removed
860 else if ( Cache
[ BrokenPkg
]. Delete () == true && List
-> IsFlag ( BrokenPkg
, pkgOrderList :: Configured
) == false )
863 clog
<< OutputInDepth ( Depth
) << " Removing " << BrokenPkg
. FullName () << " to avoid " << End
<< endl
;
864 SmartRemove ( BrokenPkg
);
870 return _error
-> Error ( "Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s , aborting" , Pkg
. FullName (). c_str ());
871 } while ( Changed
== true );
873 // Check for reverse conflicts.
874 if ( CheckRConflicts ( Pkg
, Pkg
. RevDependsList (),
875 instVer
. VerStr ()) == false )
878 for ( PrvIterator P
= instVer
. ProvidesList ();
879 P
. end () == false ; ++ P
)
880 if ( Pkg
-> Group
!= P
. OwnerPkg ()-> Group
)
881 CheckRConflicts ( Pkg
, P
. ParentPkg (). RevDependsList (), P
. ProvideVersion ());
886 List
-> Flag ( Pkg
, pkgOrderList :: UnPacked
, pkgOrderList :: States
);
888 if ( Immediate
== true && ( instVer
-> MultiArch
& pkgCache :: Version :: Same
) == pkgCache :: Version :: Same
)
890 /* Do lockstep M-A:same unpacking in two phases:
891 First unpack all installed architectures, then the not installed.
892 This way we avoid that M-A: enabled packages are installed before
893 their older non-M-A enabled packages are replaced by newer versions */
894 bool const installed
= Pkg
-> CurrentVer
!= 0 ;
895 if ( installed
== true &&
896 ( instVer
!= Pkg
. CurrentVer () ||
897 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
898 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
900 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
901 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
903 if ( P
-> CurrentVer
== 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
904 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
905 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
907 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
910 if ( installed
== false && Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
912 for ( PkgIterator P
= Pkg
. Group (). PackageList ();
913 P
. end () == false ; P
= Pkg
. Group (). NextPkg ( P
))
915 if ( P
-> CurrentVer
!= 0 || P
== Pkg
|| List
-> IsFlag ( P
, pkgOrderList :: UnPacked
) == true ||
916 List
-> IsFlag ( P
, pkgOrderList :: Configured
) == true ||
917 Cache
[ P
]. InstallVer
== 0 || ( P
. CurrentVer () == Cache
[ P
]. InstallVer
&&
918 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
))
920 if ( SmartUnPack ( P
, false , Depth
+ 1 ) == false )
924 // packages which are already unpacked don't need to be unpacked again
925 else if (( instVer
!= Pkg
. CurrentVer () ||
926 (( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) == pkgDepCache :: ReInstall
)) &&
927 Install ( Pkg
, FileNames
[ Pkg
-> ID
]) == false )
930 if ( Immediate
== true ) {
931 // Perform immedate configuration of the package.
932 if ( SmartConfigure ( Pkg
, Depth
+ 1 ) == false )
933 _error
-> Warning ( _ ( "Could not perform immediate configuration on ' %s '. "
934 "Please see man 5 apt.conf under APT::Immediate-Configure for details. ( %d )" ), Pkg
. FullName (). c_str (), 2 );
940 // PM::OrderInstall - Installation ordering routine /*{{{*/
941 // ---------------------------------------------------------------------
943 pkgPackageManager :: OrderResult
pkgPackageManager :: OrderInstall ()
945 if ( CreateOrderList () == false )
951 clog
<< "Beginning to order" << endl
;
953 bool const ordering
=
954 _config
-> FindB ( "PackageManager::UnpackAll" , true ) ?
955 List
-> OrderUnpack ( FileNames
) : List
-> OrderCritical ();
956 if ( ordering
== false )
958 _error
-> Error ( "Internal ordering error" );
963 clog
<< "Done ordering" << endl
;
965 bool DoneSomething
= false ;
966 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
968 PkgIterator
Pkg ( Cache
,* I
);
970 if ( List
-> IsNow ( Pkg
) == false )
973 clog
<< "Skipping already done " << Pkg
. FullName () << endl
;
977 if ( List
-> IsMissing ( Pkg
) == true )
980 clog
<< "Sequence completed at " << Pkg
. FullName () << endl
;
981 if ( DoneSomething
== false )
983 _error
-> Error ( "Internal Error, ordering was unable to handle the media swap" );
990 if ( Cache
[ Pkg
]. Keep () == true &&
991 Pkg
. State () == pkgCache :: PkgIterator :: NeedsNothing
&&
992 ( Cache
[ Pkg
]. iFlags
& pkgDepCache :: ReInstall
) != pkgDepCache :: ReInstall
)
994 _error
-> Error ( "Internal Error, trying to manipulate a kept package ( %s )" , Pkg
. FullName (). c_str ());
998 // Perform a delete or an install
999 if ( Cache
[ Pkg
]. Delete () == true )
1001 if ( SmartRemove ( Pkg
) == false )
1005 if ( SmartUnPack ( Pkg
, List
-> IsFlag ( Pkg
, pkgOrderList :: Immediate
), 0 ) == false )
1007 DoneSomething
= true ;
1009 if ( ImmConfigureAll
) {
1010 /* ConfigureAll here to pick up and packages left unconfigured because they were unpacked in the
1011 "PreUnpack Checks" section */
1012 if (! ConfigureAll ())
1017 // Final run through the configure phase
1018 if ( ConfigureAll () == false )
1022 for ( pkgOrderList :: iterator I
= List
-> begin (); I
!= List
-> end (); ++ I
)
1024 if ( List
-> IsFlag (* I
, pkgOrderList :: Configured
) == false )
1026 _error
-> Error ( "Internal error, packages left unconfigured. %s " ,
1027 PkgIterator ( Cache
,* I
). FullName (). c_str ());
1034 // PM::DoInstallPostFork - compat /*{{{*/
1035 // ---------------------------------------------------------------------
1037 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
1038 pkgPackageManager :: OrderResult
1039 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
1041 APT :: Progress :: PackageManager
* progress
= new
1042 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1043 pkgPackageManager :: OrderResult res
= DoInstallPostFork ( progress
);
1048 // PM::DoInstallPostFork - Does install part that happens after the fork /*{{{*/
1049 // ---------------------------------------------------------------------
1050 pkgPackageManager :: OrderResult
1051 pkgPackageManager :: DoInstallPostFork ( APT :: Progress :: PackageManager
* progress
)
1053 bool goResult
= Go ( progress
);
1054 if ( goResult
== false )
1060 pkgPackageManager :: OrderResult
1061 pkgPackageManager :: DoInstallPostFork ( int statusFd
)
1063 bool goResult
= Go ( statusFd
);
1064 if ( goResult
== false )
1071 // PM::DoInstall - Does the installation /*{{{*/
1072 // ---------------------------------------------------------------------
1074 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
1075 pkgPackageManager :: OrderResult
1076 pkgPackageManager :: DoInstall ( int statusFd
)
1078 APT :: Progress :: PackageManager
* progress
= new
1079 APT :: Progress :: PackageManagerProgressFd ( statusFd
);
1080 OrderResult res
= DoInstall ( progress
);
1085 pkgPackageManager :: OrderResult
pkgPackageManager :: DoInstall ( int statusFd
)
1087 if ( DoInstallPreFork () == Failed
)
1090 return DoInstallPostFork ( statusFd
);
1094 // PM::DoInstall - Does the installation /*{{{*/
1095 // ---------------------------------------------------------------------
1096 /* This uses the filenames in FileNames and the information in the
1097 DepCache to perform the installation of packages.*/
1098 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
1099 pkgPackageManager :: OrderResult
1100 pkgPackageManager :: DoInstall ( APT :: Progress :: PackageManager
* progress
)
1102 if ( DoInstallPreFork () == Failed
)
1105 return DoInstallPostFork ( progress
);