Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=96a8ccfab3bf7c97e2e805978e7f37979579a084
commit 96a8ccfab3bf7c97e2e805978e7f37979579a084 Author: Michel Hermier <[email protected]> Date: Thu Nov 7 11:16:39 2013 +0100 libpacman: Move localdb functions to it's own files. diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am index 23fd768..293f4e4 100644 --- a/lib/libpacman/Makefile.am +++ b/lib/libpacman/Makefile.am @@ -8,7 +8,8 @@ localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ DB_TARGETS = \ - db/fakedb.c + db/fakedb.c \ + db/localdb.c HASH_TARGETS = \ hash/md5driver.c \ diff --git a/lib/libpacman/be_files.c b/lib/libpacman/be_files.c index 856096b..85f64f3 100644 --- a/lib/libpacman/be_files.c +++ b/lib/libpacman/be_files.c @@ -39,6 +39,7 @@ /* pacman-g2 */ +#include "db/localdb.h" #include "util/log.h" #include "util/stringlist.h" #include "util.h" @@ -57,71 +58,6 @@ static inline int islocal(pmdb_t *db) } static -pmlist_t *_pacman_localdb_test(pmdb_t *db) -{ - struct dirent *ent; - char path[PATH_MAX]; - struct stat buf; - pmlist_t *ret = _pacman_list_new(); - - while ((ent = readdir(db->handle)) != NULL) { - snprintf(path, PATH_MAX, "%s/%s", db->path, ent->d_name); - stat(path, &buf); - if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..") || !S_ISDIR(buf.st_mode)) { - continue; - } - snprintf(path, PATH_MAX, "%s/%s/desc", db->path, ent->d_name); - if(stat(path, &buf)) - { - snprintf(path, LOG_STR_LEN, _("%s: description file is missing"), ent->d_name); - ret = _pacman_stringlist_append(ret, path); - } - snprintf(path, PATH_MAX, "%s/%s/depends", db->path, ent->d_name); - if(stat(path, &buf)) - { - snprintf(path, LOG_STR_LEN, _("%s: dependency information is missing"), ent->d_name); - ret = _pacman_stringlist_append(ret, path); - } - snprintf(path, PATH_MAX, "%s/%s/files", db->path, ent->d_name); - if(stat(path, &buf)) - { - snprintf(path, LOG_STR_LEN, _("%s: file list is missing"), ent->d_name); - ret = _pacman_stringlist_append(ret, path); - } - } - - return(ret); -} - -static -int _pacman_localdb_open(pmdb_t *db) -{ - db->handle = opendir(db->path); - ASSERT(db->handle != NULL, RET_ERR(PM_ERR_DB_OPEN, -1)); - - return 0; -} - -static -void _pacman_localdb_close(pmdb_t *db) -{ - if(db->handle) { - closedir(db->handle); - db->handle = NULL; - } -} - -static -void _pacman_localdb_rewind(pmdb_t *db) -{ - if(db->handle == NULL) { - return; - } - - rewinddir(db->handle); -} - -static pmlist_t *_pacman_syncdb_test(pmdb_t *db) { /* testing sync dbs is not supported */ diff --git a/lib/libpacman/db/localdb.c b/lib/libpacman/db/localdb.c new file mode 100644 index 0000000..f9aafb4 --- /dev/null +++ b/lib/libpacman/db/localdb.c @@ -0,0 +1,113 @@ +/* + * localdb.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 "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_localdb_test(pmdb_t *db) +{ + struct dirent *ent; + char path[PATH_MAX]; + struct stat buf; + pmlist_t *ret = _pacman_list_new(); + + while ((ent = readdir(db->handle)) != NULL) { + snprintf(path, PATH_MAX, "%s/%s", db->path, ent->d_name); + stat(path, &buf); + if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..") || !S_ISDIR(buf.st_mode)) { + continue; + } + snprintf(path, PATH_MAX, "%s/%s/desc", db->path, ent->d_name); + if(stat(path, &buf)) + { + snprintf(path, LOG_STR_LEN, _("%s: description file is missing"), ent->d_name); + ret = _pacman_stringlist_append(ret, path); + } + snprintf(path, PATH_MAX, "%s/%s/depends", db->path, ent->d_name); + if(stat(path, &buf)) + { + snprintf(path, LOG_STR_LEN, _("%s: dependency information is missing"), ent->d_name); + ret = _pacman_stringlist_append(ret, path); + } + snprintf(path, PATH_MAX, "%s/%s/files", db->path, ent->d_name); + if(stat(path, &buf)) + { + snprintf(path, LOG_STR_LEN, _("%s: file list is missing"), ent->d_name); + ret = _pacman_stringlist_append(ret, path); + } + } + + return(ret); +} + +int _pacman_localdb_open(pmdb_t *db) +{ + db->handle = opendir(db->path); + ASSERT(db->handle != NULL, RET_ERR(PM_ERR_DB_OPEN, -1)); + + return 0; +} + +void _pacman_localdb_close(pmdb_t *db) +{ + if(db->handle) { + closedir(db->handle); + db->handle = NULL; + } +} + +void _pacman_localdb_rewind(pmdb_t *db) +{ + if(db->handle == NULL) { + return; + } + + rewinddir(db->handle); +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h new file mode 100644 index 0000000..8fcee51 --- /dev/null +++ b/lib/libpacman/db/localdb.h @@ -0,0 +1,33 @@ +/* + * localdb.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_LOCALDB_H +#define _PACMAN_LOCALDB_H + +#include "db.h" + +pmlist_t *_pacman_localdb_test(pmdb_t *db); +int _pacman_localdb_open(pmdb_t *db); +void _pacman_localdb_close(pmdb_t *db); +void _pacman_localdb_rewind(pmdb_t *db); + +#endif /* _PACMAN_LOCALDB_H */ + +/* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
