]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
1a84aea54d5504ed2c0ceb126c2e64f68104290a
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
4 /* ######################################################################
6 CacheFile - Simple wrapper class for opening, generating and whatnot
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.
12 ##################################################################### */
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>
28 // CacheFile::CacheFile - Constructor /*{{{*/
29 // ---------------------------------------------------------------------
31 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
35 // CacheFile::~CacheFile - Destructor /*{{{*/
36 // ---------------------------------------------------------------------
38 pkgCacheFile::~pkgCacheFile()
44 _system
->UnLock(true);
47 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
48 // ---------------------------------------------------------------------
50 bool pkgCacheFile::BuildCaches(OpProgress
&Progress
,bool WithLock
)
53 if (_system
->Lock() == false)
56 if (_config
->FindB("Debug::NoLocking",false) == true)
59 if (_error
->PendingError() == true)
62 // Read the source list
64 if (List
.ReadMainList() == false)
65 return _error
->Error(_("The list of sources could not be read."));
68 bool Res
= pkgMakeStatusCache(List
,Progress
,&Map
,!WithLock
);
71 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
73 /* This sux, remove it someday */
74 if (_error
->empty() == false)
75 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
77 Cache
= new pkgCache(Map
);
78 if (_error
->PendingError() == true)
83 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
84 // ---------------------------------------------------------------------
86 bool pkgCacheFile::Open(OpProgress
&Progress
,bool WithLock
)
88 if (BuildCaches(Progress
,WithLock
) == false)
92 Policy
= new pkgPolicy(Cache
);
93 if (_error
->PendingError() == true)
95 if (ReadPinFile(*Policy
) == false)
98 // Create the dependency cache
99 DCache
= new pkgDepCache(Cache
,Policy
);
100 if (_error
->PendingError() == true)
103 DCache
->Init(&Progress
);
105 if (_error
->PendingError() == true)
113 // CacheFile::Close - close the cache files /*{{{*/
114 // ---------------------------------------------------------------------
116 void pkgCacheFile::Close()
122 _system
->UnLock(true);