]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
* cmdline/apt-get.cc:
[apt.git] / apt-pkg / cachefile.cc
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
23 #include <apti18n.h>
24 /*}}}*/
25
26 // CacheFile::CacheFile - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* */
29 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
30 {
31 }
32 /*}}}*/
33 // CacheFile::~CacheFile - Destructor /*{{{*/
34 // ---------------------------------------------------------------------
35 /* */
36 pkgCacheFile::~pkgCacheFile()
37 {
38 delete DCache;
39 delete Policy;
40 delete Cache;
41 delete Map;
42 _system->UnLock(true);
43 }
44 /*}}}*/
45 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
46 // ---------------------------------------------------------------------
47 /* */
48 bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
49 {
50 if (WithLock == true)
51 if (_system->Lock() == false)
52 return false;
53
54 if (_config->FindB("Debug::NoLocking",false) == true)
55 WithLock = false;
56
57 if (_error->PendingError() == true)
58 return false;
59
60 // Read the source list
61 pkgSourceList List;
62 if (List.ReadMainList() == false)
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)
73 _error->Warning(_("You may want to run apt-get update to correct these problems"));
74
75 Cache = new pkgCache(Map);
76 if (_error->PendingError() == true)
77 return false;
78 return true;
79 }
80 /*}}}*/
81 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
82 // ---------------------------------------------------------------------
83 /* */
84 bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
85 {
86 if (BuildCaches(Progress,WithLock) == false)
87 return false;
88
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;
95
96 // Create the dependency cache
97 DCache = new pkgDepCache(Cache,Policy);
98 if (_error->PendingError() == true)
99 return false;
100
101 DCache->Init(&Progress);
102 Progress.Done();
103 if (_error->PendingError() == true)
104 return false;
105
106 return true;
107 }
108 /*}}}*/
109
110 // CacheFile::Close - close the cache files /*{{{*/
111 // ---------------------------------------------------------------------
112 /* */
113 void 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 /*}}}*/