Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=b5ea3f7f714c2674c776e24425aa44072db087b0

commit b5ea3f7f714c2674c776e24425aa44072db087b0
Author: Michel Hermier <[email protected]>
Date:   Sun Apr 27 13:25:20 2014 +0200

libpacman: More libpacman::Database methodifications.

diff --git a/lib/libpacman/db.cpp b/lib/libpacman/db.cpp
index ff0e60b..bdad96d 100644
--- a/lib/libpacman/db.cpp
+++ b/lib/libpacman/db.cpp
@@ -175,23 +175,13 @@ int Database::read(pmpkg_t *info, unsigned int inforeq)
int Database::write(pmpkg_t *info, unsigned int inforeq)
{
ASSERT(info != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
-
-       if(ops->write != NULL) {
-               return ops->write(this, info, inforeq);
-       } else {
-               RET_ERR(PM_ERR_WRONG_ARGS, -1); // Not supported
-       }
+       RET_ERR(PM_ERR_WRONG_ARGS, -1); // Not supported
}

int Database::remove(pmpkg_t *info)
{
ASSERT(info != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
-
-       if(ops->remove != NULL) {
-               return ops->remove(this, info);
-       } else {
-               RET_ERR(PM_ERR_WRONG_ARGS, -1); // Not supported
-       }
+       RET_ERR(PM_ERR_WRONG_ARGS, -1); // Not supported
}

/* Reads dbpath/treename.lastupdate and populates *ts with the contents.
diff --git a/lib/libpacman/db.h b/lib/libpacman/db.h
index ac7f350..6226275 100644
--- a/lib/libpacman/db.h
+++ b/lib/libpacman/db.h
@@ -47,8 +47,6 @@ typedef struct __pmdb_ops_t pmdb_ops_t;

struct __pmdb_ops_t {
int (*read)(libpacman::Database *db, pmpkg_t *info, unsigned int inforeq);
-       int (*write)(libpacman::Database *db, pmpkg_t *info, unsigned int 
inforeq); /* Optional */
-       int (*remove)(libpacman::Database *db, pmpkg_t *info); /* Optional */
};

namespace libpacman {
diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp
index 5405f33..a9efe6c 100644
--- a/lib/libpacman/db/localdb.cpp
+++ b/lib/libpacman/db/localdb.cpp
@@ -48,12 +48,6 @@
using namespace libpacman;

static
-int _pacman_localdb_write(Database *db, pmpkg_t *info, unsigned int inforeq);
-
-static
-int _pacman_localdb_remove(Database *db, pmpkg_t *info);
-
-static
int _pacman_localpkg_file_reader(Database *db, pmpkg_t *pkg, unsigned int 
flags, unsigned int flags_masq, const char *file, int (*reader)(pmpkg_t *, FILE 
*))
{
int ret = 0;
@@ -116,13 +110,13 @@ _pacman_localpkg_read(pmpkg_t *pkg, unsigned int flags)
static int
_pacman_localpkg_write(pmpkg_t *pkg, unsigned int flags)
{
-       return _pacman_localdb_write(pkg->database, pkg, flags);
+       return pkg->database->write(pkg, flags);
}

static int
_pacman_localpkg_remove(pmpkg_t *pkg)
{
-       return _pacman_localdb_remove(pkg->database, pkg);
+       return pkg->database->remove(pkg);
}

static const
@@ -387,18 +381,16 @@ void _pacman_localdb_write_stringlist(const char *entry, 
const pmlist_t *values,
}
}

-static
-int _pacman_localdb_write(Database *db, pmpkg_t *info, unsigned int inforeq)
+int LocalDatabase::write(pmpkg_t *info, unsigned int inforeq)
{
FILE *fp = NULL;
char path[PATH_MAX];
mode_t oldmask;
int retval = 0;

-       ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(info != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));

-       snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, 
info->version);
+       snprintf(path, PATH_MAX, "%s/%s-%s", this->path, info->name, 
info->version);
oldmask = umask(0000);
mkdir(path, 0755);
/* make sure we have a sane umask */
@@ -406,9 +398,9 @@ int _pacman_localdb_write(Database *db, pmpkg_t *info, 
unsigned int inforeq)

/* DESC */
if(inforeq & INFRQ_DESC) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, 
info->version);
+               snprintf(path, PATH_MAX, "%s/%s-%s/desc", this->path, 
info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/desc"), db->treename);
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/desc"), treename);
retval = 1;
goto cleanup;
}
@@ -440,9 +432,9 @@ int _pacman_localdb_write(Database *db, pmpkg_t *info, 
unsigned int inforeq)

/* FILES */
if(inforeq & INFRQ_FILES) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, 
info->name, info->version);
+               snprintf(path, PATH_MAX, "%s/%s-%s/files", this->path, 
info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/files"), db->treename);
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/files"), treename);
retval = -1;
goto cleanup;
}
@@ -454,9 +446,9 @@ int _pacman_localdb_write(Database *db, pmpkg_t *info, 
unsigned int inforeq)

/* DEPENDS */
if(inforeq & INFRQ_DEPENDS) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, 
info->name, info->version);
+               snprintf(path, PATH_MAX, "%s/%s-%s/depends", this->path, 
info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/depends"), db->treename);
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/depends"), treename);
retval = -1;
goto cleanup;
}
@@ -481,15 +473,13 @@ cleanup:
return(retval);
}

-static
-int _pacman_localdb_remove(Database *db, pmpkg_t *info)
+int LocalDatabase::remove(pmpkg_t *info)
{
char path[PATH_MAX];

-       ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(info != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));

-       snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, 
info->version);
+       snprintf(path, PATH_MAX, "%s/%s-%s", this->path, info->name, 
info->version);
if(_pacman_rmrf(path) == -1) {
return(-1);
}
@@ -499,8 +489,6 @@ int _pacman_localdb_remove(Database *db, pmpkg_t *info)

const pmdb_ops_t _pacman_localdb_ops = {
.read = _pacman_localdb_read,
-       .write = _pacman_localdb_write,
-       .remove = _pacman_localdb_remove,
};

LocalDatabase::LocalDatabase(pmhandle_t *handle, const char *treename)
diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h
index 8fcd6d9..e37b815 100644
--- a/lib/libpacman/db/localdb.h
+++ b/lib/libpacman/db/localdb.h
@@ -45,6 +45,9 @@ public:
virtual pmpkg_t *readpkg(unsigned int inforeq);
virtual pmpkg_t *scan(const char *target, unsigned int inforeq);

+       virtual int write(pmpkg_t *info, unsigned int inforeq);
+       virtual int remove(pmpkg_t *info);
+
protected:
virtual int open(int flags, time_t *timestamp);
};
diff --git a/lib/libpacman/db/syncdb.cpp b/lib/libpacman/db/syncdb.cpp
index 1516d87..1e5be5c 100644
--- a/lib/libpacman/db/syncdb.cpp
+++ b/lib/libpacman/db/syncdb.cpp
@@ -340,8 +340,6 @@ int _pacman_syncdb_read(Database *db, pmpkg_t *info, 
unsigned int inforeq)

const pmdb_ops_t _pacman_syncdb_ops = {
.read = _pacman_syncdb_read,
-       .write = NULL,
-       .remove = NULL,
};

SyncDatabase::SyncDatabase(pmhandle_t *handle, const char *treename)
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to