X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/c53766c774f15b1763101f845e27feec7ac3b176..4e2df38650d114e6f258d18c097e636c4d79bf61:/ftparchive/cachedb.cc diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 450a8a47c..9e93dff05 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cachedb.cc,v 1.4 2002/11/22 07:19:51 doogie Exp $ +// $Id: cachedb.cc,v 1.7 2004/05/08 19:41:01 mdz Exp $ /* ###################################################################### CacheDB @@ -16,6 +16,7 @@ #include "cachedb.h" +#include #include #include #include @@ -29,6 +30,8 @@ /* This opens the DB2 file for caching package information */ bool CacheDB::ReadyDB(string DB) { + int err; + ReadOnly = _config->FindB("APT::FTPArchive::ReadOnlyDB",false); // Close the old DB @@ -39,7 +42,7 @@ bool CacheDB::ReadyDB(string DB) corrupted DB */ if (DBFailed() == true) { - _error->Warning("DB was corrupted, file renamed to %s.old",DBFile.c_str()); + _error->Warning(_("DB was corrupted, file renamed to %s.old"),DBFile.c_str()); rename(DBFile.c_str(),(DBFile+".old").c_str()); } @@ -49,13 +52,26 @@ bool CacheDB::ReadyDB(string DB) if (DB.empty()) return true; - - if ((errno = db_open(DB.c_str(),DB_HASH, + + db_create(&Dbp, NULL, 0); + if ((err = Dbp->open(Dbp, NULL, DB.c_str(), NULL, DB_HASH, (ReadOnly?DB_RDONLY:DB_CREATE), - 0644,0,0,&Dbp)) != 0) + 0644)) != 0) { - Dbp = 0; - return _error->Errno("db_open","Unable to open DB2 file %s",DB.c_str()); + if (err == DB_OLD_VERSION) + { + _error->Warning(_("DB is old, attempting to upgrade %s"),DBFile.c_str()); + err = Dbp->upgrade(Dbp, DB.c_str(), 0); + if (!err) + err = Dbp->open(Dbp, NULL, DB.c_str(), NULL, DB_HASH, + (ReadOnly?DB_RDONLY:DB_CREATE), 0644); + + } + if (err) + { + Dbp = 0; + return _error->Error(_("Unable to open DB file %s: %s"),DB.c_str(), db_strerror(err)); + } } DBFile = DB; @@ -95,7 +111,7 @@ bool CacheDB::SetFile(string FileName,struct stat St,FileFd *Fd) { CurStat.mtime = htonl(St.st_mtime); CurStat.Flags = 0; - _error->Warning("File date has changed %s",FileName.c_str()); + _error->Warning(_("File date has changed %s"),FileName.c_str()); } } else @@ -136,7 +152,7 @@ bool CacheDB::LoadControl() return false; if (Control.Control == 0) - return _error->Error("Archive has no control record"); + return _error->Error(_("Archive has no control record")); // Write back the control information InitQuery("cl"); @@ -225,7 +241,7 @@ bool CacheDB::Finish() { // Optimize away some writes. if (CurStat.Flags == OldStat.Flags && - CurStat.mtime == OldStat.st_mtime) + CurStat.mtime == OldStat.mtime) return true; // Write the stat information @@ -246,15 +262,9 @@ bool CacheDB::Clean() /* I'm not sure what VERSION_MINOR should be here.. 2.4.14 certainly needs the lower one and 2.7.7 needs the upper.. */ -#if DB_VERSION_MAJOR >= 2 && DB_VERSION_MINOR >= 7 DBC *Cursor; - if ((errno = Dbp->cursor(Dbp,0,&Cursor,0)) != 0) - return _error->Error("Unable to get a cursor"); -#else - DBC *Cursor; - if ((errno = Dbp->cursor(Dbp,0,&Cursor)) != 0) - return _error->Error("Unable to get a cursor"); -#endif + if ((errno = Dbp->cursor(Dbp, NULL, &Cursor, 0)) != 0) + return _error->Error(_("Unable to get a cursor")); DBT Key; DBT Data;