]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
4 /* ######################################################################
6 CacheFile - Simple wrapper class for opening, generating and whatnot
8 This class implements a simple 2 line mechanism to open various sorts
9 of caches. It can operate as root, as not root, show progress and so on,
10 it transparently handles everything necessary.
12 ##################################################################### */
14 // Include Files /*{{{*/
16 #pragma implementation "apt-pkg/cachefile.h"
19 #include <apt-pkg/cachefile.h>
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/sourcelist.h>
22 #include <apt-pkg/pkgcachegen.h>
23 #include <apt-pkg/configuration.h>
24 #include <apt-pkg/policy.h>
25 #include <apt-pkg/pkgsystem.h>
30 // CacheFile::CacheFile - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
37 // CacheFile::~CacheFile - Destructor /*{{{*/
38 // ---------------------------------------------------------------------
40 pkgCacheFile::~pkgCacheFile()
46 _system
->UnLock(true);
49 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
50 // ---------------------------------------------------------------------
52 bool pkgCacheFile::BuildCaches(OpProgress
&Progress
,bool WithLock
)
55 if (_system
->Lock() == false)
58 if (_config
->FindB("Debug::NoLocking",false) == true)
61 if (_error
->PendingError() == true)
64 // Read the source list
66 if (List
.ReadMainList() == false)
67 return _error
->Error(_("The list of sources could not be read."));
70 bool Res
= pkgMakeStatusCache(List
,Progress
,&Map
,!WithLock
);
73 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
75 /* This sux, remove it someday */
76 if (_error
->empty() == false)
77 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
79 Cache
= new pkgCache(Map
);
80 if (_error
->PendingError() == true)
85 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
86 // ---------------------------------------------------------------------
88 bool pkgCacheFile::Open(OpProgress
&Progress
,bool WithLock
)
90 if (BuildCaches(Progress
,WithLock
) == false)
94 Policy
= new pkgPolicy(Cache
);
95 if (_error
->PendingError() == true)
97 if (ReadPinFile(*Policy
) == false)
100 // Create the dependency cache
101 DCache
= new pkgDepCache(Cache
,Policy
);
102 if (_error
->PendingError() == true)
105 DCache
->Init(&Progress
);
107 if (_error
->PendingError() == true)
114 // CacheFile::Close - close the cache files /*{{{*/
115 // ---------------------------------------------------------------------
117 void pkgCacheFile::Close()
123 _system
->UnLock(true);