]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
Check if makefile name matches the package name
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Feb 2023 10:49:06 +0000 (10:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Feb 2023 10:49:06 +0000 (10:49 +0000)
This is quite important because the build process relies on it.

Fixes: #13041 - pakfire-builder confuses on wrong .nm file name
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/dist.c
src/libpakfire/include/pakfire/linter.h [new file with mode: 0644]
src/libpakfire/include/pakfire/util.h
src/libpakfire/linter.c [new file with mode: 0644]
src/libpakfire/util.c

index 8ba32a72653e616589b439054e221597dda0177b..9f6777562446ccf31c33990a3fb1ae63639f6ced 100644 (file)
@@ -232,6 +232,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/jail.c \
        src/libpakfire/key.c \
        src/libpakfire/keystore.c \
+       src/libpakfire/linter.c \
        src/libpakfire/logging.c \
        src/libpakfire/mount.c \
        src/libpakfire/package.c \
@@ -272,6 +273,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/jail.h \
        src/libpakfire/include/pakfire/key.h \
        src/libpakfire/include/pakfire/keystore.h \
+       src/libpakfire/include/pakfire/linter.h \
        src/libpakfire/include/pakfire/logging.h \
        src/libpakfire/include/pakfire/mount.h \
        src/libpakfire/include/pakfire/package.h \
index a5a9feaf247745cc0c96919e6231c60afec80879..61ed0a4f6d497c42fd073c529f61fb5b427502de 100644 (file)
@@ -28,6 +28,7 @@
 #include <pakfire/arch.h>
 #include <pakfire/dist.h>
 #include <pakfire/downloader.h>
+#include <pakfire/linter.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/packager.h>
@@ -409,6 +410,11 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
        if (r)
                goto ERROR;
 
+       // Perform some linting
+       r = pakfire_lint_makefile(pakfire, makefile, path, pkg);
+       if (r)
+               goto ERROR;
+
        // Create a packager
        r = pakfire_packager_create(&packager, pakfire, pkg);
        if (r)
diff --git a/src/libpakfire/include/pakfire/linter.h b/src/libpakfire/include/pakfire/linter.h
new file mode 100644 (file)
index 0000000..3c3626a
--- /dev/null
@@ -0,0 +1,31 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# 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 3 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, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_LINTER_H
+#define PAKFIRE_LINTER_H
+
+#include <pakfire/package.h>
+#include <pakfire/pakfire.h>
+#include <pakfire/parser.h>
+
+int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile,
+       const char* path, struct pakfire_package* pkg);
+
+#endif /* PAKFIRE_LINTER_H */
index 162235ca67a8f44f70711b258731405145ab32c4..f0742169e57aaa142c9a73b2f446ff572c6488aa 100644 (file)
@@ -39,6 +39,8 @@ char* pakfire_unquote_in_place(char* s);
 int pakfire_path_exists(const char* path);
 time_t pakfire_path_age(const char* path);
 
+int pakfire_path_strip_extension(char* path);
+
 const char* pakfire_basename(const char* path);
 const char* pakfire_dirname(const char* path);
 
diff --git a/src/libpakfire/linter.c b/src/libpakfire/linter.c
new file mode 100644 (file)
index 0000000..f1c41f4
--- /dev/null
@@ -0,0 +1,75 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# 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 3 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, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/linter.h>
+#include <pakfire/logging.h>
+#include <pakfire/package.h>
+#include <pakfire/pakfire.h>
+#include <pakfire/parser.h>
+#include <pakfire/string.h>
+#include <pakfire/util.h>
+
+static int pakfire_lint_makefile_name(struct pakfire* pakfire,
+               const char* path, struct pakfire_package* pkg) {
+       char basename[PATH_MAX];
+       int r;
+
+       // Fetch the package name
+       const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME);
+
+       // Check if the makefile ended on .nm
+       if (!pakfire_string_endswith(path, ".nm")) {
+               ERROR(pakfire, "Invalid extension for makefile: %s\n", path);
+               return 1;
+       }
+
+       // Determine the basename of the file
+       r = pakfire_string_set(basename, pakfire_basename(path));
+       if (r)
+               return r;
+
+       // Remove the file extension
+       r = pakfire_path_strip_extension(basename);
+       if (r) {
+               ERROR(pakfire, "Could not strip extension from makefile: %m\n");
+               return r;
+       }
+
+       // Check if the package name matches
+       if (strcmp(basename, name) != 0) {
+               ERROR(pakfire, "%s: Makefile has a different package name (%s)\n",
+                       path, name);
+               return 1;
+       }
+
+       return 0;
+}
+
+int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile,
+               const char* path, struct pakfire_package* pkg) {
+       int r;
+
+       // Check makefile name
+       r = pakfire_lint_makefile_name(pakfire, path, pkg);
+       if (r)
+               return r;
+
+       return 0;
+}
index cc4fbdcc8b9db0eeb400afe808bd62bc3be83e96..442ddc0a03e126087d2cabbe774210fc134f5058 100644 (file)
@@ -153,6 +153,19 @@ time_t pakfire_path_age(const char* path) {
        return -1;
 }
 
+int pakfire_path_strip_extension(char* path) {
+       char* ext = strrchr(path, '.');
+
+       // If . could not be found, we return an error.
+       if (!ext)
+               return 1;
+
+       // Otherwise, we will terminate the string
+       *ext = '\0';
+
+       return 0;
+}
+
 int pakfire_file_write(struct pakfire* pakfire, const char* path,
                uid_t owner, gid_t group, mode_t mode, const char* format, ...) {
        va_list args;