Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=29cf8adc2e3cd91b196925fd2d34aea4f5a9f1cf
commit 29cf8adc2e3cd91b196925fd2d34aea4f5a9f1cf Author: Michel Hermier <[email protected]> Date: Wed May 7 15:59:24 2014 +0200 libpacman: Remove Package::handle in favor of subclass dedicated variables. diff --git a/lib/libpacman/db.h b/lib/libpacman/db.h index 0040e46..dc7b15b 100644 --- a/lib/libpacman/db.h +++ b/lib/libpacman/db.h @@ -76,7 +76,6 @@ public: char *path; char treename[PATH_MAX]; - void *handle; time_t cache_timestamp; pmlist_t *pkgcache; pmlist_t *grpcache; diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp index 4e9912f..6f3ae05 100644 --- a/lib/libpacman/db/localdb.cpp +++ b/lib/libpacman/db/localdb.cpp @@ -156,7 +156,7 @@ pmlist_t *LocalDatabase::test() const struct stat buf; pmlist_t *ret = _pacman_list_new(); - while ((ent = readdir(handle)) != NULL) { + while ((ent = readdir(m_dir)) != NULL) { snprintf(path, PATH_MAX, "%s/%s", this->path, ent->d_name); stat(path, &buf); if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..") || !S_ISDIR(buf.st_mode)) { @@ -196,28 +196,28 @@ int LocalDatabase::open(int flags, time_t *timestamp) RET_ERR(PM_ERR_SYSTEM, -1); } } - handle = opendir(path); - ASSERT(handle != NULL, RET_ERR(PM_ERR_DB_OPEN, -1)); + m_dir = opendir(path); + ASSERT(m_dir != NULL, RET_ERR(PM_ERR_DB_OPEN, -1)); gettimestamp(timestamp); return 0; } int LocalDatabase::close() { - if(handle) { - closedir(handle); - handle = NULL; + if(m_dir) { + closedir(m_dir); + m_dir = NULL; } return 0; } int LocalDatabase::rewind() { - if(handle == NULL) { + if(m_dir == NULL) { return -1; } - rewinddir(handle); + rewinddir(m_dir); return 0; } @@ -227,7 +227,7 @@ Package *LocalDatabase::readpkg(unsigned int inforeq) struct stat sbuf; char path[PATH_MAX]; - while((ent = readdir(handle)) != NULL) { + while((ent = readdir(m_dir)) != NULL) { if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) { continue; } @@ -254,7 +254,7 @@ Package *LocalDatabase::scan(const char *target, unsigned int inforeq) rewind(); /* search for a specific package (by name only) */ - while((ent = readdir(handle)) != NULL) { + while((ent = readdir(m_dir)) != NULL) { if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) { continue; } diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h index ea531e5..6eec84b 100644 --- a/lib/libpacman/db/localdb.h +++ b/lib/libpacman/db/localdb.h @@ -24,6 +24,8 @@ #include "db.h" #include "package.h" +#include <dirent.h> + extern const pmdb_ops_t _pacman_localdb_ops; @@ -66,6 +68,9 @@ public: protected: virtual int open(int flags, time_t *timestamp); + +private: + DIR *m_dir; }; } diff --git a/lib/libpacman/db/syncdb.cpp b/lib/libpacman/db/syncdb.cpp index 10e061f..75fc42f 100644 --- a/lib/libpacman/db/syncdb.cpp +++ b/lib/libpacman/db/syncdb.cpp @@ -76,12 +76,12 @@ SyncDatabase *SyncPackage::database() const } static -int _pacman_syncpkg_file_reader(Database *db, Package *pkg, unsigned int flags, unsigned int flags_masq, int (*reader)(Package *, FILE *)) +int _pacman_syncpkg_file_reader(SyncDatabase *db, Package *pkg, unsigned int flags, unsigned int flags_masq, int (*reader)(Package *, FILE *)) { int ret = 0; if((flags & flags_masq) != 0) { - FILE *fp = _pacman_archive_read_fropen(db->handle); + FILE *fp = _pacman_archive_read_fropen(db->m_archive); ASSERT(fp != NULL, RET_ERR(PM_ERR_MEMORY, -1)); ret = reader(pkg, fp); @@ -103,7 +103,7 @@ int SyncPackage::read(unsigned int flags) while (!descdone || !depsdone) { struct archive_entry *entry = NULL; - if (archive_read_next_header(database->handle, &entry) != ARCHIVE_OK) + if (archive_read_next_header(database->m_archive, &entry) != ARCHIVE_OK) return -1; const char *pathname = archive_entry_pathname(entry); if (!suffixcmp(pathname, "/desc")) { @@ -207,10 +207,10 @@ int SyncDatabase::open(int flags, time_t *timestamp) snprintf(dbpath, PATH_MAX, "%s" PM_EXT_DB, path); if(stat(dbpath, &buf) != 0) { // db is not there, we'll open it later - handle = NULL; + m_archive = NULL; return 0; } - if((handle = _pacman_archive_read_open_all_file(dbpath)) == NULL) { + if((m_archive = _pacman_archive_read_open_all_file(dbpath)) == NULL) { //return 0 here to be able to update the damaged db with pacman -Syy RET_ERR(PM_ERR_DB_OPEN, 0); } @@ -222,9 +222,9 @@ int SyncDatabase::open(int flags, time_t *timestamp) int SyncDatabase::close() { - if(handle) { - archive_read_finish(handle); - handle = NULL; + if(m_archive) { + archive_read_finish(m_archive); + m_archive = NULL; } return 0; } @@ -239,15 +239,15 @@ Package *SyncDatabase::readpkg(unsigned int inforeq) { struct archive_entry *entry = NULL; - if(!handle) { + if(!m_archive) { rewind(); } - if(!handle) { + if(!m_archive) { return NULL; } for(;;) { - if(archive_read_next_header(handle, &entry) != ARCHIVE_OK) { + if(archive_read_next_header(m_archive, &entry) != ARCHIVE_OK) { return NULL; } // make sure it's a directory @@ -271,7 +271,7 @@ Package *SyncDatabase::scan(const char *target, unsigned int inforeq) rewind(); /* search for a specific package (by name only) */ - while (archive_read_next_header(handle, &entry) == ARCHIVE_OK) { + while (archive_read_next_header(m_archive, &entry) == ARCHIVE_OK) { // make sure it's a directory const char *pathname = archive_entry_pathname(entry); if (pathname[strlen(pathname)-1] != '/') @@ -293,12 +293,12 @@ Package *SyncDatabase::scan(const char *target, unsigned int inforeq) } static -int _pacman_syncdb_file_reader(Database *db, Package *info, unsigned int inforeq, unsigned int inforeq_masq, int (*reader)(Package *, FILE *)) +int _pacman_syncdb_file_reader(SyncDatabase *db, Package *info, unsigned int inforeq, unsigned int inforeq_masq, int (*reader)(Package *, FILE *)) { int ret = 0; if(inforeq & inforeq_masq) { - FILE *fp = _pacman_archive_read_fropen(db->handle); + FILE *fp = _pacman_archive_read_fropen(db->m_archive); ASSERT(fp != NULL, RET_ERR(PM_ERR_MEMORY, -1)); ret = reader(info, fp); @@ -308,7 +308,7 @@ int _pacman_syncdb_file_reader(Database *db, Package *info, unsigned int inforeq } static -int _pacman_syncdb_read(Database *db, Package *info, unsigned int inforeq) +int _pacman_syncdb_read(SyncDatabase *db, Package *info, unsigned int inforeq) { int descdone = 0, depsdone = 0; @@ -320,7 +320,7 @@ int _pacman_syncdb_read(Database *db, Package *info, unsigned int inforeq) while (!descdone || !depsdone) { struct archive_entry *entry = NULL; - if (archive_read_next_header(db->handle, &entry) != ARCHIVE_OK) + if (archive_read_next_header(db->m_archive, &entry) != ARCHIVE_OK) return -1; const char *pathname = archive_entry_pathname(entry); if (!suffixcmp(pathname, "/desc")) { diff --git a/lib/libpacman/db/syncdb.h b/lib/libpacman/db/syncdb.h index 880dd12..4008088 100644 --- a/lib/libpacman/db/syncdb.h +++ b/lib/libpacman/db/syncdb.h @@ -24,6 +24,8 @@ #include "db.h" #include "package.h" +#include <archive.h> + extern const pmdb_ops_t _pacman_syncdb_ops; @@ -61,6 +63,9 @@ public: protected: virtual int open(int flags, time_t *timestamp); + +public: // FIXME: Make private + struct archive *m_archive; }; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
