]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
G++3 fixes from Randolph
[apt.git] / apt-pkg / cachefile.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: cachefile.cc,v 1.6 2001/03/13 06:51:46 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 #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>
24 #include <apt-pkg/policy.h>
25 #include <apt-pkg/pkgsystem.h>
26
27 #include <apti18n.h>
28 /*}}}*/
29
30 // CacheFile::CacheFile - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
32 /* */
33 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
34 {
35 }
36 /*}}}*/
37 // CacheFile::~CacheFile - Destructor /*{{{*/
38 // ---------------------------------------------------------------------
39 /* */
40 pkgCacheFile::~pkgCacheFile()
41 {
42 delete DCache;
43 delete Policy;
44 delete Cache;
45 delete Map;
46 _system->UnLock(true);
47 }
48 /*}}}*/
49 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
50 // ---------------------------------------------------------------------
51 /* */
52 bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
53 {
54 if (WithLock == true)
55 if (_system->Lock() == false)
56 return false;
57
58 if (_error->PendingError() == true)
59 return false;
60
61 // Read the source list
62 pkgSourceList List;
63 if (List.ReadMainList() == false)
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)
74 _error->Warning(_("You may want to run apt-get update to correct these problems"));
75
76 Cache = new pkgCache(Map);
77 if (_error->PendingError() == true)
78 return false;
79
80 // The policy engine
81 Policy = new pkgPolicy(Cache);
82 if (_error->PendingError() == true)
83 return false;
84 if (ReadPinFile(*Policy) == false)
85 return false;
86
87 // Create the dependency cache
88 DCache = new pkgDepCache(Cache,Policy);
89 if (_error->PendingError() == true)
90 return false;
91
92 DCache->Init(&Progress);
93 Progress.Done();
94 if (_error->PendingError() == true)
95 return false;
96
97 return true;
98 }
99 /*}}}*/
100
101 // CacheFile::Close - close the cache files /*{{{*/
102 // ---------------------------------------------------------------------
103 /* */
104 void pkgCacheFile::Close()
105 {
106 delete DCache;
107 delete Policy;
108 delete Cache;
109 delete Map;
110 _system->UnLock(true);
111
112 Map = 0;
113 DCache = 0;
114 Policy = 0;
115 Cache = 0;
116 }
117 /*}}}*/