add the various foldmarkers in apt-pkg & cmdline (no code change)
[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 /*{{{*/
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
AL
50{
51 if (WithLock == true)
b2e465d6
AL
52 if (_system->Lock() == false)
53 return false;
2d11135a 54
c37b9502
AL
55 if (_config->FindB("Debug::NoLocking",false) == true)
56 WithLock = false;
57
2d11135a
AL
58 if (_error->PendingError() == true)
59 return false;
60
61 // Read the source list
62 pkgSourceList List;
63 if (List.ReadMainList() == false)
b2e465d6
AL
64 return _error->Error(_("The list of sources could not be read."));
65
66 // Read the caches
67 bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
68 Progress.Done();
69 if (Res == false)
70 return _error->Error(_("The package lists or status file could not be parsed or opened."));
71
72 /* This sux, remove it someday */
73 if (_error->empty() == false)
a7c835af 74 _error->Warning(_("You may want to run apt-get update to correct these problems"));
b2e465d6
AL
75
76 Cache = new pkgCache(Map);
77 if (_error->PendingError() == true)
78 return false;
0077d829
AL
79 return true;
80}
81 /*}}}*/
82// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
83// ---------------------------------------------------------------------
84/* */
85bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
86{
87 if (BuildCaches(Progress,WithLock) == false)
88 return false;
2d11135a 89
b2e465d6
AL
90 // The policy engine
91 Policy = new pkgPolicy(Cache);
92 if (_error->PendingError() == true)
93 return false;
94 if (ReadPinFile(*Policy) == false)
95 return false;
2d11135a
AL
96
97 // Create the dependency cache
b2e465d6
AL
98 DCache = new pkgDepCache(Cache,Policy);
99 if (_error->PendingError() == true)
100 return false;
101
102 DCache->Init(&Progress);
803fafcb 103 Progress.Done();
2d11135a
AL
104 if (_error->PendingError() == true)
105 return false;
2d11135a
AL
106
107 return true;
108}
109 /*}}}*/
b2e465d6
AL
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 /*}}}*/