'apt-get update' no longer does 'Building Dependency Tree'.
[ntk/apt.git] / apt-pkg / cachefile.cc
CommitLineData
2d11135a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
0077d829 3// $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
2d11135a
AL
4/* ######################################################################
5
6 CacheFile - Simple wrapper class for opening, generating and whatnot
7
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.
11
12 ##################################################################### */
13 /*}}}*/
14// Include Files /*{{{*/
15#ifdef __GNUG__
16#pragma implementation "apt-pkg/cachefile.h"
17#endif
18
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>
b2e465d6
AL
24#include <apt-pkg/policy.h>
25#include <apt-pkg/pkgsystem.h>
26
27#include <apti18n.h>
2d11135a
AL
28 /*}}}*/
29
30// CacheFile::CacheFile - Constructor /*{{{*/
31// ---------------------------------------------------------------------
32/* */
b2e465d6 33pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
2d11135a
AL
34{
35}
36 /*}}}*/
b2e465d6 37// CacheFile::~CacheFile - Destructor /*{{{*/
2d11135a
AL
38// ---------------------------------------------------------------------
39/* */
40pkgCacheFile::~pkgCacheFile()
41{
b2e465d6
AL
42 delete DCache;
43 delete Policy;
2d11135a
AL
44 delete Cache;
45 delete Map;
b2e465d6 46 _system->UnLock(true);
2d11135a
AL
47}
48 /*}}}*/
0077d829 49// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
2d11135a
AL
50// ---------------------------------------------------------------------
51/* */
0077d829 52bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
2d11135a
AL
53{
54 if (WithLock == true)
b2e465d6
AL
55 if (_system->Lock() == false)
56 return false;
2d11135a 57
c37b9502
AL
58 if (_config->FindB("Debug::NoLocking",false) == true)
59 WithLock = false;
60
2d11135a
AL
61 if (_error->PendingError() == true)
62 return false;
63
64 // Read the source list
65 pkgSourceList List;
66 if (List.ReadMainList() == false)
b2e465d6
AL
67 return _error->Error(_("The list of sources could not be read."));
68
69 // Read the caches
70 bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
71 Progress.Done();
72 if (Res == false)
73 return _error->Error(_("The package lists or status file could not be parsed or opened."));
74
75 /* This sux, remove it someday */
76 if (_error->empty() == false)
a7c835af 77 _error->Warning(_("You may want to run apt-get update to correct these problems"));
b2e465d6
AL
78
79 Cache = new pkgCache(Map);
80 if (_error->PendingError() == true)
81 return false;
0077d829
AL
82 return true;
83}
84 /*}}}*/
85// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
86// ---------------------------------------------------------------------
87/* */
88bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
89{
90 if (BuildCaches(Progress,WithLock) == false)
91 return false;
2d11135a 92
b2e465d6
AL
93 // The policy engine
94 Policy = new pkgPolicy(Cache);
95 if (_error->PendingError() == true)
96 return false;
97 if (ReadPinFile(*Policy) == false)
98 return false;
2d11135a
AL
99
100 // Create the dependency cache
b2e465d6
AL
101 DCache = new pkgDepCache(Cache,Policy);
102 if (_error->PendingError() == true)
103 return false;
104
105 DCache->Init(&Progress);
803fafcb 106 Progress.Done();
2d11135a
AL
107 if (_error->PendingError() == true)
108 return false;
2d11135a
AL
109
110 return true;
111}
112 /*}}}*/
b2e465d6
AL
113
114// CacheFile::Close - close the cache files /*{{{*/
115// ---------------------------------------------------------------------
116/* */
117void pkgCacheFile::Close()
118{
119 delete DCache;
120 delete Policy;
121 delete Cache;
122 delete Map;
123 _system->UnLock(true);
124
125 Map = 0;
126 DCache = 0;
127 Policy = 0;
128 Cache = 0;
129}
130 /*}}}*/