From ec47b094d8f38eb7da3bf05c14f9d53bac0dba89 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 13 Mar 2021 18:03:09 +0000 Subject: [PATCH] Move pakfire_read_makefile to dist It fits better here Signed-off-by: Michael Tremer --- src/libpakfire/dist.c | 75 ++++++++++++++++++++++ src/libpakfire/include/pakfire/constants.h | 3 - src/libpakfire/pakfire.c | 72 --------------------- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index a7f46ed94..f7c5f06be 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,80 @@ #include #include +#define PAKFIRE_MACROS_DIR "/usr/lib/pakfire/macros" +#define PAKFIRE_MACROS_GLOB_PATTERN PAKFIRE_MACROS_DIR "/*.macro" + +PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, + const char* path, struct pakfire_parser_error** error) { + int r = 1; + + *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); + if (!*parser) { + r = 1; + goto ERROR; + } + + // XXX set defaults + + // Find all macros + char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN); + if (!macros) + goto ERROR; + + DEBUG(pakfire, "Searching for macros in %s\n", macros); + + glob_t globmacros; + r = glob(macros, 0, NULL, &globmacros); + free(macros); + + // Handle any errors + switch (r) { + case 0: + case GLOB_NOMATCH: + break; + + case GLOB_NOSPACE: + errno = ENOMEM; + goto ERROR; + + case GLOB_ABORTED: + goto ERROR; + + default: + ERROR(pakfire, "glob() returned an unhandled error: %d\n", r); + goto ERROR; + } + + DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc); + + // Read all macros + for (unsigned int i = 0; i < globmacros.gl_pathc; i++) { + // Parse the file + r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error); + if (r) + goto ERROR; + } + + globfree(&globmacros); + + // Finally, parse the makefile + r = pakfire_parser_read_file(*parser, path, error); + if (r) + goto ERROR; + + return 0; + +ERROR: + globfree(&globmacros); + + if (*parser) { + pakfire_parser_unref(*parser); + *parser = NULL; + } + + return r; +} + static int pakfire_dist_download_source(Pakfire pakfire, const char* filename, const char* cache_path) { struct pakfire_downloader* downloader; diff --git a/src/libpakfire/include/pakfire/constants.h b/src/libpakfire/include/pakfire/constants.h index d8d1c85f2..d4870eef2 100644 --- a/src/libpakfire/include/pakfire/constants.h +++ b/src/libpakfire/include/pakfire/constants.h @@ -33,9 +33,6 @@ #define CACHE_PATH "/var/cache/pakfire" -#define PAKFIRE_MACROS_DIR "/usr/lib/pakfire/macros" -#define PAKFIRE_MACROS_GLOB_PATTERN PAKFIRE_MACROS_DIR "/*.macro" - #ifdef PAKFIRE_PRIVATE // The file format that this version generates diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index b63325268..a5eb1f015 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -776,74 +775,3 @@ PAKFIRE_EXPORT void pakfire_log(Pakfire pakfire, int priority, const char* file, // Restore errno errno = saved_errno; } - -PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, - const char* path, struct pakfire_parser_error** error) { - int r = 1; - - *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); - if (!*parser) { - r = 1; - goto ERROR; - } - - // XXX set defaults - - // Find all macros - char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN); - if (!macros) - goto ERROR; - - DEBUG(pakfire, "Searching for macros in %s\n", macros); - - glob_t globmacros; - r = glob(macros, 0, NULL, &globmacros); - free(macros); - - // Handle any errors - switch (r) { - case 0: - case GLOB_NOMATCH: - break; - - case GLOB_NOSPACE: - errno = ENOMEM; - goto ERROR; - - case GLOB_ABORTED: - goto ERROR; - - default: - ERROR(pakfire, "glob() returned an unhandled error: %d\n", r); - goto ERROR; - } - - DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc); - - // Read all macros - for (unsigned int i = 0; i < globmacros.gl_pathc; i++) { - // Parse the file - r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error); - if (r) - goto ERROR; - } - - globfree(&globmacros); - - // Finally, parse the makefile - r = pakfire_parser_read_file(*parser, path, error); - if (r) - goto ERROR; - - return 0; - -ERROR: - globfree(&globmacros); - - if (*parser) { - pakfire_parser_unref(*parser); - *parser = NULL; - } - - return r; -} -- 2.47.2