]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/cachefile.cc
releasing version 0.7.26~exp4
[apt.git] / apt-pkg / cachefile.cc
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
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#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>
20#include <apt-pkg/policy.h>
21#include <apt-pkg/pkgsystem.h>
22#include <apt-pkg/acquire-item.h>
23#include <apt-pkg/fileutl.h>
24
25#include <apti18n.h>
26 /*}}}*/
27// CacheFile::CacheFile - Constructor /*{{{*/
28// ---------------------------------------------------------------------
29/* */
30pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
31{
32}
33 /*}}}*/
34// CacheFile::~CacheFile - Destructor /*{{{*/
35// ---------------------------------------------------------------------
36/* */
37pkgCacheFile::~pkgCacheFile()
38{
39 delete DCache;
40 delete Policy;
41 delete Cache;
42 delete Map;
43 _system->UnLock(true);
44}
45 /*}}}*/
46// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
47// ---------------------------------------------------------------------
48/* */
49bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
50{
51 const bool ErrorWasEmpty = _error->empty();
52 if (WithLock == true)
53 if (_system->Lock() == false)
54 return false;
55
56 if (_config->FindB("Debug::NoLocking",false) == true)
57 WithLock = false;
58
59 if (_error->PendingError() == true)
60 return false;
61
62 // Read the source list
63 pkgSourceList List;
64 if (List.ReadMainList() == false)
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 */
74 if (ErrorWasEmpty == true && _error->empty() == false)
75 _error->Warning(_("You may want to run apt-get update to correct these problems"));
76
77 Cache = new pkgCache(Map);
78 if (_error->PendingError() == true)
79 return false;
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;
90
91 // The policy engine
92 Policy = new pkgPolicy(Cache);
93 if (_error->PendingError() == true)
94 return false;
95
96 if (ReadPinFile(*Policy) == false || ReadPinDir(*Policy) == false)
97 return false;
98
99 // Create the dependency cache
100 DCache = new pkgDepCache(Cache,Policy);
101 if (_error->PendingError() == true)
102 return false;
103
104 DCache->Init(&Progress);
105 Progress.Done();
106 if (_error->PendingError() == true)
107 return false;
108
109 return true;
110}
111 /*}}}*/
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 /*}}}*/