~jr/ubuntu/oneiric/apt/bzr-get-rename

« back to all changes in this revision

Viewing changes to ftparchive/cachedb.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2005-03-07 20:08:33 UTC
  • Revision ID: james.westby@ubuntu.com-20050307200833-0lxdgg2cb4oculdv
Tags: 0.6.35
* Merge apt--mvo--0 (incorporates 0.6.34ubuntu1):
  - Implement MaxSize and MaxAge in apt.cron.daily, to prevent the cache
    from growing too large (Ubuntu #6761)
  - some comments about the pkgAcqMetaSig::Custom600Headers() added
  - use gpg --with-colons
  - commented the ftp no_proxy unseting in methods/ftp.cc
  - added support for "Acquire::gpgv::options" in methods/gpgv.cc
* Merge bubulle@debian.org--2005/apt--main--0
  - Make capitalization more consistent
  - Un-fuzzy translations resulting from capitalization changes
  - Italian translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description                                                          /*{{{*/
3
 
// $Id: cachedb.cc,v 1.3 2001/05/29 03:50:33 jgg Exp $
 
3
// $Id: cachedb.cc,v 1.7 2004/05/08 19:41:01 mdz Exp $
4
4
/* ######################################################################
5
5
 
6
6
   CacheDB
16
16
 
17
17
#include "cachedb.h"
18
18
 
 
19
#include <apti18n.h>
19
20
#include <apt-pkg/error.h>
20
21
#include <apt-pkg/md5.h>
21
22
#include <apt-pkg/strutl.h>
29
30
/* This opens the DB2 file for caching package information */
30
31
bool CacheDB::ReadyDB(string DB)
31
32
{
 
33
   int err;
 
34
 
32
35
   ReadOnly = _config->FindB("APT::FTPArchive::ReadOnlyDB",false);
33
36
   
34
37
   // Close the old DB
39
42
      corrupted DB */
40
43
   if (DBFailed() == true)
41
44
   {
42
 
      _error->Warning("DB was corrupted, file renamed to %s.old",DBFile.c_str());
 
45
      _error->Warning(_("DB was corrupted, file renamed to %s.old"),DBFile.c_str());
43
46
      rename(DBFile.c_str(),(DBFile+".old").c_str());
44
47
   }
45
48
   
49
52
   
50
53
   if (DB.empty())
51
54
      return true;
52
 
   
53
 
   if ((errno = db_open(DB.c_str(),DB_HASH,
 
55
 
 
56
   db_create(&Dbp, NULL, 0);
 
57
   if ((err = Dbp->open(Dbp, NULL, DB.c_str(), NULL, DB_HASH,
54
58
                        (ReadOnly?DB_RDONLY:DB_CREATE),
55
 
                        0644,0,0,&Dbp)) != 0)
 
59
                        0644)) != 0)
56
60
   {
57
 
      Dbp = 0;
58
 
      return _error->Errno("db_open","Unable to open DB2 file %s",DB.c_str());
 
61
      if (err == DB_OLD_VERSION)
 
62
      {
 
63
          _error->Warning(_("DB is old, attempting to upgrade %s"),DBFile.c_str());
 
64
          err = Dbp->upgrade(Dbp, DB.c_str(), 0);
 
65
          if (!err)
 
66
             err = Dbp->open(Dbp, NULL, DB.c_str(), NULL, DB_HASH,
 
67
                            (ReadOnly?DB_RDONLY:DB_CREATE), 0644);
 
68
 
 
69
      }
 
70
      if (err)
 
71
      {
 
72
          Dbp = 0;
 
73
          return _error->Error(_("Unable to open DB file %s: %s"),DB.c_str(), db_strerror(err));
 
74
      }
59
75
   }
60
76
   
61
77
   DBFile = DB;
91
107
   // Lookup the stat info and confirm the file is unchanged
92
108
   if (Get() == true)
93
109
   {
94
 
      if (CurStat.st_mtime != htonl(St.st_mtime))
 
110
      if (CurStat.mtime != htonl(St.st_mtime))
95
111
      {
96
 
         CurStat.st_mtime = htonl(St.st_mtime);
 
112
         CurStat.mtime = htonl(St.st_mtime);
97
113
         CurStat.Flags = 0;
98
 
         _error->Warning("File date has changed %s",FileName.c_str());
 
114
         _error->Warning(_("File date has changed %s"),FileName.c_str());
99
115
      }      
100
116
   }      
101
117
   else
102
118
   {
103
 
      CurStat.st_mtime = htonl(St.st_mtime);
 
119
      CurStat.mtime = htonl(St.st_mtime);
104
120
      CurStat.Flags = 0;
105
121
   }   
106
122
   CurStat.Flags = ntohl(CurStat.Flags);
136
152
      return false;
137
153
 
138
154
   if (Control.Control == 0)
139
 
      return _error->Error("Archive has no control record");
 
155
      return _error->Error(_("Archive has no control record"));
140
156
   
141
157
   // Write back the control information
142
158
   InitQuery("cl");
225
241
{
226
242
   // Optimize away some writes.
227
243
   if (CurStat.Flags == OldStat.Flags &&
228
 
       CurStat.st_mtime == OldStat.st_mtime)
 
244
       CurStat.mtime == OldStat.mtime)
229
245
      return true;
230
246
   
231
247
   // Write the stat information
246
262
 
247
263
   /* I'm not sure what VERSION_MINOR should be here.. 2.4.14 certainly
248
264
      needs the lower one and 2.7.7 needs the upper.. */
249
 
#if DB_VERSION_MAJOR >= 2 && DB_VERSION_MINOR >= 7
250
 
   DBC *Cursor;
251
 
   if ((errno = Dbp->cursor(Dbp,0,&Cursor,0)) != 0)
252
 
      return _error->Error("Unable to get a cursor");
253
 
#else
254
 
   DBC *Cursor;
255
 
   if ((errno = Dbp->cursor(Dbp,0,&Cursor)) != 0)
256
 
      return _error->Error("Unable to get a cursor");
257
 
#endif
 
265
   DBC *Cursor;
 
266
   if ((errno = Dbp->cursor(Dbp, NULL, &Cursor, 0)) != 0)
 
267
      return _error->Error(_("Unable to get a cursor"));
258
268
   
259
269
   DBT Key;
260
270
   DBT Data;