]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
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>
27 // CacheFile::CacheFile - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
30 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
34 // CacheFile::~CacheFile - Destructor /*{{{*/
35 // ---------------------------------------------------------------------
37 pkgCacheFile::~pkgCacheFile()
43 _system
->UnLock(true);
46 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
47 // ---------------------------------------------------------------------
49 bool pkgCacheFile::BuildCaches(OpProgress
&Progress
,bool WithLock
)
52 if (_system
->Lock() == false)
55 if (_config
->FindB("Debug::NoLocking",false) == true)
58 if (_error
->PendingError() == true)
61 // Read the source list
63 if (List
.ReadMainList() == false)
64 return _error
->Error(_("The list of sources could not be read."));
67 bool Res
= pkgMakeStatusCache(List
,Progress
,&Map
,!WithLock
);
70 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
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"));
76 Cache
= new pkgCache(Map
);
77 if (_error
->PendingError() == true)
82 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
83 // ---------------------------------------------------------------------
85 bool pkgCacheFile::Open(OpProgress
&Progress
,bool WithLock
)
87 if (BuildCaches(Progress
,WithLock
) == false)
91 Policy
= new pkgPolicy(Cache
);
92 if (_error
->PendingError() == true)
94 if (ReadPinFile(*Policy
) == false)
97 // Create the dependency cache
98 DCache
= new pkgDepCache(Cache
,Policy
);
99 if (_error
->PendingError() == true)
102 DCache
->Init(&Progress
);
104 if (_error
->PendingError() == true)
110 // CacheFile::Close - close the cache files /*{{{*/
111 // ---------------------------------------------------------------------
113 void pkgCacheFile::Close()
119 _system
->UnLock(true);