]> git.saurik.com Git - apt.git/blame - apt-pkg/cachefile.cc
* methods/mirror.{cc,h}:
[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 /*{{{*/
2d11135a
AL
15#include <apt-pkg/cachefile.h>
16#include <apt-pkg/error.h>
17#include <apt-pkg/sourcelist.h>
18#include <apt-pkg/pkgcachegen.h>
19#include <apt-pkg/configuration.h>
b2e465d6
AL
20#include <apt-pkg/policy.h>
21#include <apt-pkg/pkgsystem.h>
22
23#include <apti18n.h>
2d11135a
AL
24 /*}}}*/
25
26// CacheFile::CacheFile - Constructor /*{{{*/
27// ---------------------------------------------------------------------
28/* */
b2e465d6 29pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
2d11135a
AL
30{
31}
32 /*}}}*/
b2e465d6 33// CacheFile::~CacheFile - Destructor /*{{{*/
2d11135a
AL
34// ---------------------------------------------------------------------
35/* */
36pkgCacheFile::~pkgCacheFile()
37{
b2e465d6
AL
38 delete DCache;
39 delete Policy;
2d11135a
AL
40 delete Cache;
41 delete Map;
b2e465d6 42 _system->UnLock(true);
2d11135a
AL
43}
44 /*}}}*/
0077d829 45// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
2d11135a
AL
46// ---------------------------------------------------------------------
47/* */
0077d829 48bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
2d11135a
AL
49{
50 if (WithLock == true)
b2e465d6
AL
51 if (_system->Lock() == false)
52 return false;
2d11135a 53
c37b9502
AL
54 if (_config->FindB("Debug::NoLocking",false) == true)
55 WithLock = false;
56
2d11135a
AL
57 if (_error->PendingError() == true)
58 return false;
59
60 // Read the source list
61 pkgSourceList List;
62 if (List.ReadMainList() == false)
b2e465d6
AL
63 return _error->Error(_("The list of sources could not be read."));
64
65 // Read the caches
66 bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
67 Progress.Done();
68 if (Res == false)
69 return _error->Error(_("The package lists or status file could not be parsed or opened."));
70
71 /* This sux, remove it someday */
72 if (_error->empty() == false)
a7c835af 73 _error->Warning(_("You may want to run apt-get update to correct these problems"));
b2e465d6
AL
74
75 Cache = new pkgCache(Map);
76 if (_error->PendingError() == true)
77 return false;
0077d829
AL
78 return true;
79}
80 /*}}}*/
81// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
82// ---------------------------------------------------------------------
83/* */
84bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
85{
86 if (BuildCaches(Progress,WithLock) == false)
87 return false;
2d11135a 88
b2e465d6
AL
89 // The policy engine
90 Policy = new pkgPolicy(Cache);
91 if (_error->PendingError() == true)
92 return false;
93 if (ReadPinFile(*Policy) == false)
94 return false;
2d11135a
AL
95
96 // Create the dependency cache
b2e465d6
AL
97 DCache = new pkgDepCache(Cache,Policy);
98 if (_error->PendingError() == true)
99 return false;
100
101 DCache->Init(&Progress);
803fafcb 102 Progress.Done();
2d11135a
AL
103 if (_error->PendingError() == true)
104 return false;
2d11135a
AL
105
106 return true;
107}
108 /*}}}*/
b2e465d6
AL
109
110// CacheFile::Close - close the cache files /*{{{*/
111// ---------------------------------------------------------------------
112/* */
113void pkgCacheFile::Close()
114{
115 delete DCache;
116 delete Policy;
117 delete Cache;
118 delete Map;
119 _system->UnLock(true);
120
121 Map = 0;
122 DCache = 0;
123 Policy = 0;
124 Cache = 0;
125}
126 /*}}}*/