X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/eb2bc4f206faf5b8c67f09f3a92b3dea453e2b87..9209ec4701d9f6c21d4ae9ebb648d94a1f32665a:/ftparchive/cachedb.cc?ds=inline diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 0e6078642..64638459a 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -10,10 +10,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "cachedb.h" -#endif - #include "cachedb.h" #include @@ -30,7 +26,7 @@ // CacheDB::ReadyDB - Ready the DB2 /*{{{*/ // --------------------------------------------------------------------- /* This opens the DB2 file for caching package information */ -bool CacheDB::ReadyDB(string DB) +bool CacheDB::ReadyDB(string const &DB) { int err; @@ -106,9 +102,9 @@ bool CacheDB::OpenFile() // --------------------------------------------------------------------- /* This gets the size from the database if it's there. If we need * to look at the file, also get the mtime from the file. */ -bool CacheDB::GetFileStat() +bool CacheDB::GetFileStat(bool const &doStat) { - if ((CurStat.Flags & FlSize) == FlSize) + if ((CurStat.Flags & FlSize) == FlSize && doStat == false) { /* Already worked out the file size */ } @@ -164,9 +160,9 @@ bool CacheDB::GetCurStat() /*}}}*/ // CacheDB::GetFileInfo - Get all the info about the file /*{{{*/ // --------------------------------------------------------------------- -bool CacheDB::GetFileInfo(string FileName, bool DoControl, bool DoContents, - bool GenContentsOnly, - bool DoMD5, bool DoSHA1, bool DoSHA256) +bool CacheDB::GetFileInfo(string const &FileName, bool const &DoControl, bool const &DoContents, + bool const &GenContentsOnly, bool const &DoMD5, bool const &DoSHA1, + bool const &DoSHA256, bool const &checkMtime) { this->FileName = FileName; @@ -175,22 +171,26 @@ bool CacheDB::GetFileInfo(string FileName, bool DoControl, bool DoContents, return false; } OldStat = CurStat; - - if (GetFileStat() == false) + + if (GetFileStat(checkMtime) == false) { delete Fd; Fd = NULL; return false; } + /* if mtime changed, update CurStat from disk */ + if (checkMtime == true && OldStat.mtime != CurStat.mtime) + CurStat.Flags = FlSize; + Stats.Bytes += CurStat.FileSize; Stats.Packages++; - if (DoControl && LoadControl() == false - || DoContents && LoadContents(GenContentsOnly) == false - || DoMD5 && GetMD5(false) == false - || DoSHA1 && GetSHA1(false) == false - || DoSHA256 && GetSHA256(false) == false) + if ((DoControl && LoadControl() == false) + || (DoContents && LoadContents(GenContentsOnly) == false) + || (DoMD5 && GetMD5(false) == false) + || (DoSHA1 && GetSHA1(false) == false) + || (DoSHA256 && GetSHA256(false) == false)) { delete Fd; Fd = NULL; @@ -251,7 +251,7 @@ bool CacheDB::LoadControl() // CacheDB::LoadContents - Load the File Listing /*{{{*/ // --------------------------------------------------------------------- /* */ -bool CacheDB::LoadContents(bool GenOnly) +bool CacheDB::LoadContents(bool const &GenOnly) { // Try to read the control information out of the DB. if ((CurStat.Flags & FlContents) == FlContents) @@ -301,7 +301,7 @@ static string bytes2hex(uint8_t *bytes, size_t length) { return string(space); } -static inline unsigned char xdig2num(char dig) { +static inline unsigned char xdig2num(char const &dig) { if (isdigit(dig)) return dig - '0'; if ('a' <= dig && dig <= 'f') return dig - 'a' + 10; if ('A' <= dig && dig <= 'F') return dig - 'A' + 10; @@ -322,7 +322,7 @@ static void hex2bytes(uint8_t *bytes, const char *hex, int length) { // CacheDB::GetMD5 - Get the MD5 hash /*{{{*/ // --------------------------------------------------------------------- /* */ -bool CacheDB::GetMD5(bool GenOnly) +bool CacheDB::GetMD5(bool const &GenOnly) { // Try to read the control information out of the DB. if ((CurStat.Flags & FlMD5) == FlMD5) @@ -353,7 +353,7 @@ bool CacheDB::GetMD5(bool GenOnly) // CacheDB::GetSHA1 - Get the SHA1 hash /*{{{*/ // --------------------------------------------------------------------- /* */ -bool CacheDB::GetSHA1(bool GenOnly) +bool CacheDB::GetSHA1(bool const &GenOnly) { // Try to read the control information out of the DB. if ((CurStat.Flags & FlSHA1) == FlSHA1) @@ -384,7 +384,7 @@ bool CacheDB::GetSHA1(bool GenOnly) // CacheDB::GetSHA256 - Get the SHA256 hash /*{{{*/ // --------------------------------------------------------------------- /* */ -bool CacheDB::GetSHA256(bool GenOnly) +bool CacheDB::GetSHA256(bool const &GenOnly) { // Try to read the control information out of the DB. if ((CurStat.Flags & FlSHA256) == FlSHA256) @@ -453,21 +453,21 @@ bool CacheDB::Clean() memset(&Data,0,sizeof(Data)); while ((errno = Cursor->c_get(Cursor,&Key,&Data,DB_NEXT)) == 0) { - const char *Colon = (char *)Key.data; - for (; Colon != (char *)Key.data+Key.size && *Colon != ':'; Colon++); - if ((char *)Key.data+Key.size - Colon > 2) + const char *Colon = (char*)memrchr(Key.data, ':', Key.size); + if (Colon) { - if (stringcmp((char *)Key.data,Colon,"st") == 0 || - stringcmp((char *)Key.data,Colon,"cn") == 0 || - stringcmp((char *)Key.data,Colon,"cl") == 0) + if (stringcmp(Colon + 1, (char *)Key.data+Key.size,"st") == 0 || + stringcmp(Colon + 1, (char *)Key.data+Key.size,"cl") == 0 || + stringcmp(Colon + 1, (char *)Key.data+Key.size,"cn") == 0) { - if (FileExists(string(Colon+1,(const char *)Key.data+Key.size)) == true) + if (FileExists(string((const char *)Key.data,Colon)) == true) continue; } } Cursor->c_del(Cursor,0); } + Dbp->compact(Dbp, NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL); return true; }