From: Michael Tremer Date: Wed, 10 Mar 2021 14:57:30 +0000 (+0000) Subject: dist: Add source files to packages X-Git-Tag: 0.9.28~1285^2~578 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baf0851bd47291c979992152a5c10a4b2a93ade1;p=pakfire.git dist: Add source files to packages Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 0059aec23..38b97a674 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -36,6 +36,96 @@ #include #include +static int pakfire_dist_download_source(Pakfire pakfire, const char* filename, + const char* cache_path) { + DEBUG(pakfire, "Downloading %s...\n", filename); + + return 1; +} + +static int pakfire_dist_add_source(Pakfire pakfire, struct pakfire_packager* packager, + PakfirePackage pkg, const char* filename) { + int r; + char archive_path[PATH_MAX]; + char path[PATH_MAX]; + + const char* name = pakfire_package_get_name(pkg); + + snprintf(path, sizeof(path) - 1, "sources/%s/%s", name, filename); + snprintf(archive_path, sizeof(archive_path) - 1, "files/%s", filename); + + // Download the file if it does not exist in the cache + if (pakfire_cache_access(pakfire, path, R_OK)) { + r = pakfire_dist_download_source(pakfire, filename, path); + if (r) + return r; + } + + // Make path in cache + char* cache_abspath = pakfire_get_cache_path(pakfire, path); + if (!cache_abspath) + return 1; + + // Add file to package + r = pakfire_packager_add(packager, cache_abspath, archive_path); + if (r) + goto ERROR; + + // Success + r = 0; + +ERROR: + free(cache_abspath); + + return r; +} + +static int pakfire_dist_add_sources(Pakfire pakfire, struct pakfire_packager* packager, + PakfirePackage pkg, PakfireParser makefile) { + int r; + + char* sources = pakfire_parser_get(makefile, NULL, "sources"); + if (!sources) + return 1; + + // Nothing to do if there are no sources + if (!*sources) { + free(sources); + return 0; + } + + // Split sources by space + char** sourceslist = pakfire_split_string(sources, ' '); + if (!sourceslist) { + ERROR(pakfire, "Could not split sources: %s\n", strerror(errno)); + r = 1; + goto ERROR; + } + + // Add all files one by one + for (char** source = sourceslist; *source; source++) { + DEBUG(pakfire, "Adding source file %s\n", *source); + + r = pakfire_dist_add_source(pakfire, packager, pkg, *source); + if (r) { + ERROR(pakfire, "Could not add '%s' to package: %s\n", *source, strerror(errno)); + goto ERROR; + } + } + + // Success + r = 0; + +ERROR: + if (sourceslist) { + for (char** source = sourceslist; *source; source++) + free(*source); + free(sourceslist); + } + + return r; +} + static int pakfire_dist_add_files(Pakfire pakfire, struct pakfire_packager* packager, const char* path) { int r = 1; @@ -139,6 +229,11 @@ PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* t if (r) goto ERROR; + // Add all source files (which might need to be downloaded) + r = pakfire_dist_add_sources(pakfire, packager, pkg, makefile); + if (r) + goto ERROR; + snprintf(tempfile, PATH_MAX - 1, "%s/.pakfire-dist.XXXXXX", target); // Create a temporary result file