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

commit 5d3e94c72c5cdcff303b9c4f0d2f233aa0234e8e
Author: Michel Hermier <[email protected]>
Date:   Thu Nov 7 10:49:23 2013 +0100

libpacman: Move fakedb code to it's own file.

diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am
index e1c00f1..23fd768 100644
--- a/lib/libpacman/Makefile.am
+++ b/lib/libpacman/Makefile.am
@@ -7,6 +7,9 @@ SUBDIRS = po
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@

+DB_TARGETS = \
+       db/fakedb.c
+
HASH_TARGETS = \
hash/md5driver.c \
hash/md5.c \
@@ -18,6 +21,7 @@ UTIL_TARGETS = \
util/stringlist.c

TARGETS = \
+       $(DB_TARGETS) \
$(HASH_TARGETS) \
$(UTIL_TARGETS) \
util.c \
diff --git a/lib/libpacman/add.c b/lib/libpacman/add.c
index 5a6a031..3ed5f4b 100644
--- a/lib/libpacman/add.c
+++ b/lib/libpacman/add.c
@@ -42,6 +42,7 @@
/* pacman-g2 */
#include "add.h"

+#include "db/fakedb.h"
#include "hash/md5.h"
#include "hash/sha1.h"
#include "util/list.h"
@@ -61,61 +62,6 @@
#include "handle.h"
#include "packages_transaction.h"

-static pmpkg_t *fakedb_pkg_new(pmdb_t *fakedb, const char *name)
-{
-       char *ptr, *p;
-       char *str = NULL;
-       pmpkg_t *dummy = NULL;
-
-       dummy = _pacman_pkg_new(NULL, NULL);
-       if(dummy == NULL) {
-               RET_ERR(PM_ERR_MEMORY, NULL);
-       }
-
-       /* Format: field1=value1|field2=value2|...
-        * Valid fields are "name", "version" and "depend"
-        */
-       str = strdup(name);
-       ptr = str;
-       while((p = strsep(&ptr, "|")) != NULL) {
-               char *q;
-               if(p[0] == 0) {
-                       continue;
-               }
-               q = strchr(p, '=');
-               if(q == NULL) { /* not a valid token */
-                       continue;
-               }
-               if(strncmp("name", p, q-p) == 0) {
-                       STRNCPY(dummy->name, q+1, PKG_NAME_LEN);
-               } else if(strncmp("version", p, q-p) == 0) {
-                       STRNCPY(dummy->version, q+1, PKG_VERSION_LEN);
-               } else if(strncmp("depend", p, q-p) == 0) {
-                       dummy->depends = 
_pacman_stringlist_append(dummy->depends, q+1);
-               } else {
-                       _pacman_log(PM_LOG_ERROR, _("could not parse token 
%s"), p);
-               }
-       }
-       FREE(str);
-       if(dummy->name[0] == 0 || dummy->version[0] == 0) {
-               FREEPKG(dummy);
-               RET_ERR(PM_ERR_PKG_INVALID_NAME, NULL);
-       }
-       return dummy;
-}
-
-static int add_faketarget(pmtrans_t *trans, const char *name)
-{
-       pmpkg_t *dummy = fakedb_pkg_new(NULL, name);
-
-       if (dummy == NULL)
-               return -1;
-       /* add the package to the transaction */
-       trans->packages = _pacman_list_add(trans->packages, dummy);
-
-       return(0);
-}
-
int _pacman_add_addtarget(pmtrans_t *trans, const char *name)
{
pmpkg_t *info = NULL;
@@ -131,7 +77,7 @@ int _pacman_add_addtarget(pmtrans_t *trans, const char *name)

/* Check if we need to add a fake target to the transaction. */
if(strchr(name, '|')) {
-               return(add_faketarget(trans, name));
+               return(_pacman_fakedb_addtarget(trans, name));
}

if(stat(name, &buf)) {
diff --git a/lib/libpacman/db/fakedb.c b/lib/libpacman/db/fakedb.c
new file mode 100644
index 0000000..5dddad4
--- /dev/null
+++ b/lib/libpacman/db/fakedb.c
@@ -0,0 +1,93 @@
+/*
+ *  fakedb.c
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2005 by Aurelien Foret <[email protected]>
+ *  Copyright (c) 2005 by Christian Hamar <[email protected]>
+ *  Copyright (c) 2006 by David Kimpe <[email protected]>
+ *  Copyright (c) 2005, 2006 by Miklos Vajna <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include "config.h"
+
+#include <time.h>
+
+/* pacman-g2 */
+#include "fakedb.h"
+
+#include "util/list.h"
+#include "util/stringlist.h"
+#include "package.h"
+#include "util.h"
+
+static pmpkg_t *_pacman_fakedb_pkg_new(pmdb_t *fakedb, const char *name)
+{
+       char *ptr, *p;
+       char *str = NULL;
+       pmpkg_t *dummy = NULL;
+
+       dummy = _pacman_pkg_new(NULL, NULL);
+       if(dummy == NULL) {
+               RET_ERR(PM_ERR_MEMORY, NULL);
+       }
+
+       /* Format: field1=value1|field2=value2|...
+        * Valid fields are "name", "version" and "depend"
+        */
+       str = strdup(name);
+       ptr = str;
+       while((p = strsep(&ptr, "|")) != NULL) {
+               char *q;
+               if(p[0] == 0) {
+                       continue;
+               }
+               q = strchr(p, '=');
+               if(q == NULL) { /* not a valid token */
+                       continue;
+               }
+               if(strncmp("name", p, q-p) == 0) {
+                       STRNCPY(dummy->name, q+1, PKG_NAME_LEN);
+               } else if(strncmp("version", p, q-p) == 0) {
+                       STRNCPY(dummy->version, q+1, PKG_VERSION_LEN);
+               } else if(strncmp("depend", p, q-p) == 0) {
+                       dummy->depends = 
_pacman_stringlist_append(dummy->depends, q+1);
+               } else {
+                       _pacman_log(PM_LOG_ERROR, _("could not parse token 
%s"), p);
+               }
+       }
+       FREE(str);
+       if(dummy->name[0] == 0 || dummy->version[0] == 0) {
+               FREEPKG(dummy);
+               RET_ERR(PM_ERR_PKG_INVALID_NAME, NULL);
+       }
+       return dummy;
+}
+
+int _pacman_fakedb_addtarget(pmtrans_t *trans, const char *name)
+{
+       pmpkg_t *dummy = _pacman_fakedb_pkg_new(NULL, name);
+
+       if (dummy == NULL)
+               return -1;
+       /* add the package to the transaction */
+       trans->packages = _pacman_list_add(trans->packages, dummy);
+
+       return(0);
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/db/fakedb.h b/lib/libpacman/db/fakedb.h
new file mode 100644
index 0000000..abff751
--- /dev/null
+++ b/lib/libpacman/db/fakedb.h
@@ -0,0 +1,30 @@
+/*
+ *  fakedb.h
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+#ifndef _PACMAN_FAKEDB_H
+#define _PACMAN_FAKEDB_H
+
+#include "trans.h"
+
+int _pacman_fakedb_addtarget(pmtrans_t *trans, const char *name);
+
+#endif /* _PACMAN_FAKEDB_H */
+
+/* vim: set ts=2 sw=2 noet: */
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to