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

commit 5b6ad8b0f546b65e1e91141a308cca3c4419bedb
Author: Michel Hermier <[email protected]>
Date:   Thu Nov 7 11:27:18 2013 +0100

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

diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am
index 293f4e4..0321aaa 100644
--- a/lib/libpacman/Makefile.am
+++ b/lib/libpacman/Makefile.am
@@ -9,7 +9,8 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@

DB_TARGETS = \
db/fakedb.c \
-       db/localdb.c
+       db/localdb.c \
+       db/syncdb.c

HASH_TARGETS = \
hash/md5driver.c \
diff --git a/lib/libpacman/be_files.c b/lib/libpacman/be_files.c
index 85f64f3..ba7c722 100644
--- a/lib/libpacman/be_files.c
+++ b/lib/libpacman/be_files.c
@@ -57,39 +57,6 @@ static inline int islocal(pmdb_t *db)
return strcmp(db->treename, "local") == 0;
}

-static
-pmlist_t *_pacman_syncdb_test(pmdb_t *db)
-{
-       /* testing sync dbs is not supported */
-       return _pacman_list_new();
-}
-
-static
-void _pacman_syncdb_close(pmdb_t *db)
-{
-       if(db->handle) {
-               archive_read_finish(db->handle);
-               db->handle = NULL;
-       }
-}
-
-static
-void _pacman_syncdb_rewind(pmdb_t *db)
-{
-       char dbpath[PATH_MAX];
-
-       snprintf(dbpath, PATH_MAX, "%s" PM_EXT_DB, db->path);
-       if (db->handle)
-               archive_read_finish(db->handle);
-       db->handle = archive_read_new();
-       archive_read_support_compression_all(db->handle);
-       archive_read_support_format_all(db->handle);
-       if (archive_read_open_filename(db->handle, dbpath, 
PM_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
-               archive_read_finish(db->handle);
-               db->handle = NULL;
-       }
-}
-
pmlist_t *_pacman_db_test(pmdb_t *db)
{
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, NULL));
@@ -111,23 +78,9 @@ int _pacman_db_open(pmdb_t *db)
if(ret != 0)
return ret;
} else {
-               char dbpath[PATH_MAX];
-               snprintf(dbpath, PATH_MAX, "%s" PM_EXT_DB, db->path);
-               struct stat buf;
-               if(stat(dbpath, &buf) != 0) {
-                       // db is not there, we'll open it later
-                       db->handle = NULL;
-                       return 0;
-               }
-               if((db->handle = archive_read_new()) == NULL) {
-                       RET_ERR(PM_ERR_DB_OPEN, -1);
-               }
-               archive_read_support_compression_all(db->handle);
-               archive_read_support_format_all(db->handle);
-               if(archive_read_open_filename(db->handle, dbpath, 
PM_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
-                       archive_read_finish(db->handle);
-                       RET_ERR(PM_ERR_DB_OPEN, -1);
-               }
+               ret = _pacman_syncdb_open(db);
+               if(ret != 0)
+                       return ret;
}
if(ret == 0 && _pacman_db_getlastupdate(db, db->lastupdate) == -1) {
db->lastupdate[0] = '\0';
diff --git a/lib/libpacman/db/syncdb.c b/lib/libpacman/db/syncdb.c
new file mode 100644
index 0000000..b9ebc76
--- /dev/null
+++ b/lib/libpacman/db/syncdb.c
@@ -0,0 +1,103 @@
+/*
+ *  syncdb.c
+ *
+ *  Copyright (c) 2006 by Christian Hamar <[email protected]>
+ *  Copyright (c) 2006-2008 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 <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#ifdef __sun__
+#include <strings.h>
+#endif
+#include <sys/stat.h>
+#include <dirent.h>
+#include <libintl.h>
+#include <locale.h>
+#ifdef CYGWIN
+#include <limits.h> /* PATH_MAX */
+#endif
+
+/* pacman-g2 */
+
+#include "db/localdb.h"
+#include "util/log.h"
+#include "util/stringlist.h"
+#include "util.h"
+#include "db.h"
+#include "package.h"
+#include "pacman.h"
+#include "error.h"
+#include "handle.h"
+
+pmlist_t *_pacman_syncdb_test(pmdb_t *db)
+{
+       /* testing sync dbs is not supported */
+       return _pacman_list_new();
+}
+
+int _pacman_syncdb_open(pmdb_t *db)
+{
+       char dbpath[PATH_MAX];
+       snprintf(dbpath, PATH_MAX, "%s" PM_EXT_DB, db->path);
+       struct stat buf;
+       if(stat(dbpath, &buf) != 0) {
+               // db is not there, we'll open it later
+               db->handle = NULL;
+               return 0;
+       }
+       if((db->handle = archive_read_new()) == NULL) {
+               RET_ERR(PM_ERR_DB_OPEN, -1);
+       }
+       archive_read_support_compression_all(db->handle);
+       archive_read_support_format_all(db->handle);
+       if(archive_read_open_filename(db->handle, dbpath, 
PM_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+               archive_read_finish(db->handle);
+               RET_ERR(PM_ERR_DB_OPEN, -1);
+       }
+}
+
+void _pacman_syncdb_close(pmdb_t *db)
+{
+       if(db->handle) {
+               archive_read_finish(db->handle);
+               db->handle = NULL;
+       }
+}
+
+void _pacman_syncdb_rewind(pmdb_t *db)
+{
+       char dbpath[PATH_MAX];
+
+       snprintf(dbpath, PATH_MAX, "%s" PM_EXT_DB, db->path);
+       if (db->handle)
+               archive_read_finish(db->handle);
+       db->handle = archive_read_new();
+       archive_read_support_compression_all(db->handle);
+       archive_read_support_format_all(db->handle);
+       if (archive_read_open_filename(db->handle, dbpath, 
PM_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+               archive_read_finish(db->handle);
+               db->handle = NULL;
+       }
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/db/syncdb.h b/lib/libpacman/db/syncdb.h
new file mode 100644
index 0000000..edfcdbb
--- /dev/null
+++ b/lib/libpacman/db/syncdb.h
@@ -0,0 +1,33 @@
+/*
+ *  syncdb.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_SYNCDB_H
+#define _PACMAN_SYNCDB_H
+
+#include "db.h"
+
+pmlist_t *_pacman_syncdb_test(pmdb_t *db);
+int _pacman_syncdb_open(pmdb_t *db);
+void _pacman_syncdb_close(pmdb_t *db);
+void _pacman_syncdb_rewind(pmdb_t *db);
+
+#endif /* _PACMAN_SYNCDB_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