diff options
author | Guillem Jover <guillem@debian.org> | 2011-02-25 00:21:46 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2011-03-02 07:35:00 +0100 |
commit | 9f7f2a958321d41725c0ae7f46c434fe4cbf3c6a (patch) | |
tree | 0528d3ddb0ae6d070dbe8f847288e05ddd057732 /src | |
parent | ae3500585ce59833e7b3094e1615fa273d7b8527 (diff) | |
download | dpkg-9f7f2a958321d41725c0ae7f46c434fe4cbf3c6a.tar.gz |
dpkg: Refactor infodb file existence check into new pkg_infodb_has_file()
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/depcon.c | 10 | ||||
-rw-r--r-- | src/infodb.c | 50 | ||||
-rw-r--r-- | src/infodb.h | 30 | ||||
-rw-r--r-- | src/remove.c | 18 |
5 files changed, 86 insertions, 23 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8c0e8041b..cdba38259 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ dpkg_SOURCES = \ errors.c \ filesdb.c filesdb.h \ filters.c filters.h \ + infodb.c infodb.h \ divertdb.c \ statdb.c \ help.c \ diff --git a/src/depcon.c b/src/depcon.c index 4c87fe637..1baa2d7c2 100644 --- a/src/depcon.c +++ b/src/depcon.c @@ -32,6 +32,7 @@ #include <dpkg/dpkg.h> #include <dpkg/dpkg-db.h> +#include "infodb.h" #include "main.h" struct cyclesofarlink { @@ -48,8 +49,6 @@ foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar, struct pkginfo *dependedon, struct deppossi *possi) { struct cyclesofarlink *sol; - const char *postinstfilename; - struct stat stab; if(!possi) return false; @@ -75,11 +74,8 @@ foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar, * able to do something straight away when findbreakcycle returns. */ sofar= thislink; for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) { - postinstfilename= pkgadminfile(sol->pkg,POSTINSTFILE); - if (lstat(postinstfilename,&stab)) { - if (errno == ENOENT) break; - ohshite(_("unable to check for existence of `%.250s'"),postinstfilename); - } + if (!pkg_infodb_has_file(sol->pkg, POSTINSTFILE)) + break; } /* Now we have either a package with no postinst, or the other diff --git a/src/infodb.c b/src/infodb.c new file mode 100644 index 000000000..9a4fa50d3 --- /dev/null +++ b/src/infodb.c @@ -0,0 +1,50 @@ +/* + * dpkg - main program for package management + * infodb.c - package control information database + * + * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk> + * Copyright © 2011 Guillem Jover <guillem@debian.org> + * + * This 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 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, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <compat.h> + +#include <sys/types.h> +#include <sys/stat.h> + +#include <errno.h> +#include <unistd.h> + +#include <dpkg/i18n.h> +#include <dpkg/dpkg.h> +#include <dpkg/dpkg-db.h> + +#include "infodb.h" + +bool +pkg_infodb_has_file(struct pkginfo *pkg, const char *name) +{ + const char *filename; + struct stat stab; + + filename = pkgadminfile(pkg, name); + if (lstat(filename, &stab) == 0) + return true; + else if (errno == ENOENT) + return false; + else + ohshite(_("unable to check existence of `%.250s'"), filename); +} diff --git a/src/infodb.h b/src/infodb.h new file mode 100644 index 000000000..0f211d8a5 --- /dev/null +++ b/src/infodb.h @@ -0,0 +1,30 @@ +/* + * dpkg - main program for package management + * infodb.h - package control information database + * + * Copyright © 2011 Guillem Jover <guillem@debian.org> + * + * This 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 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef DPKG_INFODB_H +#define DPKG_INFODB_H + +#include <stdbool.h> + +#include <dpkg/dpkg-db.h> + +bool pkg_infodb_has_file(struct pkginfo *pkg, const char *name); + +#endif /* DPKG_INFODB_H */ diff --git a/src/remove.c b/src/remove.c index 972236760..00dedad1f 100644 --- a/src/remove.c +++ b/src/remove.c @@ -40,6 +40,7 @@ #include <dpkg/myopt.h> #include <dpkg/triglib.h> +#include "infodb.h" #include "filesdb.h" #include "main.h" @@ -511,21 +512,6 @@ static void removal_bulk_remove_configfiles(struct pkginfo *pkg) { "purge", NULL); } -static bool -pkg_has_postrm_script(struct pkginfo *pkg) -{ - const char *postrmfilename; - struct stat stab; - - postrmfilename = pkgadminfile(pkg, POSTRMFILE); - if (!lstat(postrmfilename, &stab)) - return true; - else if (errno == ENOENT) - return false; - else - ohshite(_("unable to check existence of `%.250s'"), postrmfilename); -} - /* * This is used both by deferred_remove() in this file, and at the end of * process_archive() in archives.c if it needs to finish removing a @@ -540,7 +526,7 @@ void removal_bulk(struct pkginfo *pkg) { removal_bulk_remove_files(pkg); } - foundpostrm = pkg_has_postrm_script(pkg); + foundpostrm = pkg_infodb_has_file(pkg, POSTRMFILE); debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm); |