]> git.saurik.com Git - apt.git/blame - apt-pkg/cachefile.cc
apt-pkg/init.cc
[apt.git] / apt-pkg / cachefile.cc
CommitLineData
2d11135a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
c37b9502 3// $Id: cachefile.cc,v 1.7 2001/07/01 20:49:08 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 /*}}}*/
49// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
50// ---------------------------------------------------------------------
51/* */
52bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
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;
2d11135a 82
b2e465d6
AL
83 // The policy engine
84 Policy = new pkgPolicy(Cache);
85 if (_error->PendingError() == true)
86 return false;
87 if (ReadPinFile(*Policy) == false)
88 return false;
2d11135a
AL
89
90 // Create the dependency cache
b2e465d6
AL
91 DCache = new pkgDepCache(Cache,Policy);
92 if (_error->PendingError() == true)
93 return false;
94
95 DCache->Init(&Progress);
803fafcb 96 Progress.Done();
2d11135a
AL
97 if (_error->PendingError() == true)
98 return false;
2d11135a
AL
99
100 return true;
101}
102 /*}}}*/
b2e465d6
AL
103
104// CacheFile::Close - close the cache files /*{{{*/
105// ---------------------------------------------------------------------
106/* */
107void pkgCacheFile::Close()
108{
109 delete DCache;
110 delete Policy;
111 delete Cache;
112 delete Map;
113 _system->UnLock(true);
114
115 Map = 0;
116 DCache = 0;
117 Policy = 0;
118 Cache = 0;
119}
120 /*}}}*/