From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A69C3138334 for ; Wed, 27 Mar 2019 10:56:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 64FADE07E2; Wed, 27 Mar 2019 10:55:57 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1DF75E07E2 for ; Wed, 27 Mar 2019 10:55:56 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DA391335C7B for ; Wed, 27 Mar 2019 10:55:54 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D9D3F266 for ; Wed, 27 Mar 2019 10:55:52 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1553546641.83f3df9d2df983c10b370be423606be53536a909.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/Makefile.am libq/Makefile.in libq/cache.c libq/cache.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 83f3df9d2df983c10b370be423606be53536a909 X-VCS-Branch: master Date: Wed, 27 Mar 2019 10:55:52 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 36e373e9-e75e-40c7-9ded-d0dbd671e286 X-Archives-Hash: ab2d02a42f1e6f113a806f2b698c02ea commit: 83f3df9d2df983c10b370be423606be53536a909 Author: Fabian Groffen gentoo org> AuthorDate: Mon Mar 25 20:44:01 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon Mar 25 20:44:01 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=83f3df9d libq: split out cache-related funcs from main/qsearch Signed-off-by: Fabian Groffen gentoo.org> libq/Makefile.am | 1 + libq/Makefile.in | 24 ++++-- libq/cache.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ libq/cache.h | 50 ++++++++++++ 4 files changed, 302 insertions(+), 7 deletions(-) diff --git a/libq/Makefile.am b/libq/Makefile.am index 80b651c..26647ee 100644 --- a/libq/Makefile.am +++ b/libq/Makefile.am @@ -3,6 +3,7 @@ QFILES = \ atom.c atom.h \ basename.c basename.h \ busybox.h \ + cache.c cache.h \ colors.c colors.h \ copy_file.c copy_file.h \ eat_file.c eat_file.h \ diff --git a/libq/Makefile.in b/libq/Makefile.in index a5e43fc..6c529c2 100644 --- a/libq/Makefile.in +++ b/libq/Makefile.in @@ -241,13 +241,14 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libq_la_LIBADD = -am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \ - libq_la-copy_file.lo libq_la-eat_file.lo libq_la-hash_fd.lo \ - libq_la-human_readable.lo libq_la-md5_sha1_sum.lo \ - libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \ - libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \ - libq_la-vdb.lo libq_la-xarray.lo libq_la-xchdir.lo \ - libq_la-xmkdir.lo libq_la-xregex.lo libq_la-xsystem.lo +am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-cache.lo \ + libq_la-colors.lo libq_la-copy_file.lo libq_la-eat_file.lo \ + libq_la-hash_fd.lo libq_la-human_readable.lo \ + libq_la-md5_sha1_sum.lo libq_la-prelink.lo libq_la-profile.lo \ + libq_la-rmspace.lo libq_la-safe_io.lo libq_la-scandirat.lo \ + libq_la-set.lo libq_la-vdb.lo libq_la-xarray.lo \ + libq_la-xchdir.lo libq_la-xmkdir.lo libq_la-xregex.lo \ + libq_la-xsystem.lo am_libq_la_OBJECTS = $(am__objects_1) libq_la_OBJECTS = $(am_libq_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -1444,6 +1445,7 @@ QFILES = \ atom.c atom.h \ basename.c basename.h \ busybox.h \ + cache.c cache.h \ colors.c colors.h \ copy_file.c copy_file.h \ eat_file.c eat_file.h \ @@ -1528,6 +1530,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-atom.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-basename.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-cache.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-colors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-copy_file.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-eat_file.Plo@am__quote@ @@ -1582,6 +1585,13 @@ libq_la-basename.lo: basename.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-basename.lo `test -f 'basename.c' || echo '$(srcdir)/'`basename.c +libq_la-cache.lo: cache.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-cache.lo -MD -MP -MF $(DEPDIR)/libq_la-cache.Tpo -c -o libq_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-cache.Tpo $(DEPDIR)/libq_la-cache.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cache.c' object='libq_la-cache.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c + libq_la-colors.lo: colors.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-colors.lo -MD -MP -MF $(DEPDIR)/libq_la-colors.Tpo -c -o libq_la-colors.lo `test -f 'colors.c' || echo '$(srcdir)/'`colors.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-colors.Tpo $(DEPDIR)/libq_la-colors.Plo diff --git a/libq/cache.c b/libq/cache.c new file mode 100644 index 0000000..a130381 --- /dev/null +++ b/libq/cache.c @@ -0,0 +1,234 @@ +/* + * Copyright 2005-2019 Gentoo Foundation + * Distributed under the terms of the GNU General Public License v2 + * + * Copyright 2005-2008 Ned Ludd - + * Copyright 2005-2014 Mike Frysinger - + * Copyright 2018- Fabian Groffen - + */ + +#include "main.h" + +#include +#include +#include +#include + +#include "atom.h" +#include "cache.h" + +#ifdef EBUG +static void +cache_dump(portage_cache *cache) +{ + if (!cache) + errf("Cache is empty !"); + + printf("DEPEND : %s\n", cache->DEPEND); + printf("RDEPEND : %s\n", cache->RDEPEND); + printf("SLOT : %s\n", cache->SLOT); + printf("SRC_URI : %s\n", cache->SRC_URI); + printf("RESTRICT : %s\n", cache->RESTRICT); + printf("HOMEPAGE : %s\n", cache->HOMEPAGE); + printf("LICENSE : %s\n", cache->LICENSE); + printf("DESCRIPTION: %s\n", cache->DESCRIPTION); + printf("KEYWORDS : %s\n", cache->KEYWORDS); + printf("INHERITED : %s\n", cache->INHERITED); + printf("IUSE : %s\n", cache->IUSE); + printf("CDEPEND : %s\n", cache->CDEPEND); + printf("PDEPEND : %s\n", cache->PDEPEND); + printf("PROVIDE : %s\n", cache->PROVIDE); + printf("EAPI : %s\n", cache->EAPI); + printf("PROPERTIES : %s\n", cache->PROPERTIES); + if (!cache->atom) return; + printf("CATEGORY : %s\n", cache->atom->CATEGORY); + printf("PN : %s\n", cache->atom->PN); + printf("PV : %s\n", cache->atom->PV); + printf("PVR : %s\n", cache->atom->PVR); +} +#endif + +static portage_cache *cache_read_file_pms(const char *file); +static portage_cache *cache_read_file_md5(const char *file); + +portage_cache * +cache_read_file(int portcachedir_type, const char *file) +{ + if (portcachedir_type == CACHE_METADATA_MD5) + return(cache_read_file_md5(file)); + else if (portcachedir_type == CACHE_METADATA_PMS) + return(cache_read_file_pms(file)); + warn("Unknown metadata cache type!"); + return NULL; +} + +static portage_cache * +cache_read_file_pms(const char *file) +{ + struct stat s; + char *ptr; + FILE *f; + portage_cache *ret = NULL; + size_t len; + + if ((f = fopen(file, "r")) == NULL) + goto err; + + if (fstat(fileno(f), &s) != 0) + goto err; + len = sizeof(*ret) + s.st_size + 1; + ret = xzalloc(len); + ptr = (char*)ret; + ret->_data = ptr + sizeof(*ret); + if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size) + goto err; + + ret->atom = atom_explode(file); + ret->DEPEND = ret->_data; +#define next_line(curr, next) \ + if ((ptr = strchr(ret->curr, '\n')) == NULL) { \ + warn("Invalid cache file '%s'", file); \ + goto err; \ + } \ + ret->next = ptr+1; \ + *ptr = '\0'; + next_line(DEPEND, RDEPEND) + next_line(RDEPEND, SLOT) + next_line(SLOT, SRC_URI) + next_line(SRC_URI, RESTRICT) + next_line(RESTRICT, HOMEPAGE) + next_line(HOMEPAGE, LICENSE) + next_line(LICENSE, DESCRIPTION) + next_line(DESCRIPTION, KEYWORDS) + next_line(KEYWORDS, INHERITED) + next_line(INHERITED, IUSE) + next_line(IUSE, CDEPEND) + next_line(CDEPEND, PDEPEND) + next_line(PDEPEND, PROVIDE) + next_line(PROVIDE, EAPI) + next_line(EAPI, PROPERTIES) +#undef next_line + ptr = strchr(ptr+1, '\n'); + if (ptr == NULL) { + warn("Invalid cache file '%s' - could not find end of cache data", file); + goto err; + } + *ptr = '\0'; + + fclose(f); + + return ret; + +err: + if (f) fclose(f); + if (ret) cache_free(ret); + return NULL; +} + +static portage_cache * +cache_read_file_md5(const char *file) +{ + struct stat s; + char *ptr, *endptr; + FILE *f; + portage_cache *ret = NULL; + size_t len; + + if ((f = fopen(file, "r")) == NULL) + goto err; + + if (fstat(fileno(f), &s) != 0) + goto err; + len = sizeof(*ret) + s.st_size + 1; + ret = xzalloc(len); + ptr = (char*)ret; + ret->_data = ptr + sizeof(*ret); + if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size) + goto err; + + ret->atom = atom_explode(file); + + /* We have a block of key=value\n data. + * KEY=VALUE\n + * Where KEY does NOT contain: + * \0 \n = + * And VALUE does NOT contain: + * \0 \n + * */ +#define assign_var_cmp(keyname, cmpkey) \ + if (strncmp(keyptr, cmpkey, strlen(cmpkey)) == 0) { \ + ret->keyname = valptr; \ + continue; \ + } +#define assign_var(keyname) \ + assign_var_cmp(keyname, #keyname); + + ptr = ret->_data; + endptr = strchr(ptr, '\0'); + if (endptr == NULL) { + warn("Invalid cache file '%s' - could not find end of cache data", file); + goto err; + } + + while (ptr != NULL && ptr != endptr) { + char *keyptr; + char *valptr; + keyptr = ptr; + valptr = strchr(ptr, '='); + if (valptr == NULL) { + warn("Invalid cache file '%s' val", file); + goto err; + } + *valptr = '\0'; + valptr++; + ptr = strchr(valptr, '\n'); + if (ptr == NULL) { + warn("Invalid cache file '%s' key", file); + goto err; + } + *ptr = '\0'; + ptr++; + + assign_var(CDEPEND); + assign_var(DEPEND); + assign_var(DESCRIPTION); + assign_var(EAPI); + assign_var(HOMEPAGE); + assign_var(INHERITED); + assign_var(IUSE); + assign_var(KEYWORDS); + assign_var(LICENSE); + assign_var(PDEPEND); + assign_var(PROPERTIES); + assign_var(PROVIDE); + assign_var(RDEPEND); + assign_var(RESTRICT); + assign_var(SLOT); + assign_var(SRC_URI); + assign_var(DEFINED_PHASES); + assign_var(REQUIRED_USE); + assign_var(_eclasses_); + assign_var(_md5_); + warn("Cache file '%s' with unknown key %s", file, keyptr); + } +#undef assign_var +#undef assign_var_cmp + + fclose(f); + + return ret; + +err: + if (f) fclose(f); + if (ret) cache_free(ret); + return NULL; +} + +void +cache_free(portage_cache *cache) +{ + if (!cache) + errf("Cache is empty !"); + atom_implode(cache->atom); + free(cache); +} diff --git a/libq/cache.h b/libq/cache.h new file mode 100644 index 0000000..971417c --- /dev/null +++ b/libq/cache.h @@ -0,0 +1,50 @@ +/* + * Copyright 2005-2019 Gentoo Foundation + * Distributed under the terms of the GNU General Public License v2 + * + * Copyright 2005-2010 Ned Ludd - + * Copyright 2005-2014 Mike Frysinger - + * Copyright 2019- Fabian Groffen - + */ + +#ifndef _CACHE_H +#define _CACHE_H 1 + +typedef struct { + char *_data; + char *DEPEND; /* line 1 */ + char *RDEPEND; + char *SLOT; + char *SRC_URI; + char *RESTRICT; /* line 5 */ + char *HOMEPAGE; + char *LICENSE; + char *DESCRIPTION; + char *KEYWORDS; + char *INHERITED; /* line 10 */ + char *IUSE; + char *CDEPEND; + char *PDEPEND; + char *PROVIDE; /* line 14 */ + char *EAPI; + char *PROPERTIES; + depend_atom *atom; + /* These are MD5-Cache only */ + char *DEFINED_PHASES; + char *REQUIRED_USE; + char *_eclasses_; + char *_md5_; +} portage_cache; + +portage_cache * +cache_read_file(int portcachedir_type, const char *file); +void cache_free(portage_cache *cache); + +enum { + CACHE_EBUILD = 1, + CACHE_METADATA = 2, + CACHE_METADATA_PMS = 10, + CACHE_METADATA_MD5 = 11, +}; + +#endif