]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
96d9672c2e9527686cb0547374a6317ac279dab5
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 /*{{{*/
16 #pragma implementation "apt-pkg/cachefile.h"
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 #include <apt-pkg/acquire-item.h>
31 // CacheFile::CacheFile - Constructor /*{{{*/
32 // ---------------------------------------------------------------------
34 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
38 // CacheFile::~CacheFile - Destructor /*{{{*/
39 // ---------------------------------------------------------------------
41 pkgCacheFile::~pkgCacheFile()
47 _system
->UnLock(true);
50 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
51 // ---------------------------------------------------------------------
53 bool pkgCacheFile::BuildCaches(OpProgress
&Progress
,bool WithLock
)
56 if (_system
->Lock() == false)
59 if (_config
->FindB("Debug::NoLocking",false) == true)
62 if (_error
->PendingError() == true)
65 // Read the source list
67 if (List
.ReadMainList() == false)
68 return _error
->Error(_("The list of sources could not be read."));
71 bool Res
= pkgMakeStatusCache(List
,Progress
,&Map
,!WithLock
);
74 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
76 /* This sux, remove it someday */
77 if (_error
->empty() == false)
78 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
80 Cache
= new pkgCache(Map
);
81 if (_error
->PendingError() == true)
86 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
87 // ---------------------------------------------------------------------
89 bool pkgCacheFile::Open(OpProgress
&Progress
,bool WithLock
)
91 if (BuildCaches(Progress
,WithLock
) == false)
95 Policy
= new pkgPolicy(Cache
);
96 if (_error
->PendingError() == true)
98 if (ReadPinFile(*Policy
) == false)
101 // Create the dependency cache
102 DCache
= new pkgDepCache(Cache
,Policy
);
103 if (_error
->PendingError() == true)
106 DCache
->Init(&Progress
);
108 if (_error
->PendingError() == true)
115 // CacheFile::ListUpdate - update the cache files /*{{{*/
116 // ---------------------------------------------------------------------
118 bool pkgCacheFile::ListUpdate(pkgAcquireStatus
&Stat
, pkgSourceList
&List
)
120 pkgAcquire
Fetcher(&Stat
);
122 // Populate it with the source selection
123 if (List
.GetIndexes(&Fetcher
) == false)
127 if (Fetcher
.Run() == pkgAcquire::Failed
)
131 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
133 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
138 _error
->Warning(_("Failed to fetch %s %s\n"),
139 (*I
)->DescURI().c_str(),
140 (*I
)->ErrorText
.c_str());
144 // Clean out any old list files (if it was not a failure)
145 // Keep "APT::Get::List-Cleanup" name for compatibility, but
146 // this is really a global option for the APT library now
147 if (!Failed
&& (_config
->FindB("APT::Get::List-Cleanup",true) == true ||
148 _config
->FindB("APT::List-Cleanup",true) == true))
150 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
151 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
156 return (Failed
== false);
160 // CacheFile::Close - close the cache files /*{{{*/
161 // ---------------------------------------------------------------------
163 void pkgCacheFile::Close()
169 _system
->UnLock(true);