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