Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/740957/?format=api
{ "id": 740957, "url": "http://patchwork.ozlabs.org/api/patches/740957/?format=api", "web_url": "http://patchwork.ozlabs.org/project/lede/patch/1490009989-29321-2-git-send-email-yszhou4tech@gmail.com/", "project": { "id": 54, "url": "http://patchwork.ozlabs.org/api/projects/54/?format=api", "name": "LEDE development", "link_name": "lede", "list_id": "lede-dev.lists.infradead.org", "list_email": "lede-dev@lists.infradead.org", "web_url": "http://lede-project.org/", "scm_url": "", "webscm_url": "http://git.lede-project.org/", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1490009989-29321-2-git-send-email-yszhou4tech@gmail.com>", "list_archive_url": null, "date": "2017-03-20T11:39:49", "name": "[LEDE-DEV,opkg-lede,2/2] pkg: alternatives support", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "42e1a908a5825e0ffbbdd8ab3c96f60d974b21f9", "submitter": { "id": 65295, "url": "http://patchwork.ozlabs.org/api/people/65295/?format=api", "name": "Yousong Zhou", "email": "yszhou4tech@gmail.com" }, "delegate": { "id": 54635, "url": "http://patchwork.ozlabs.org/api/users/54635/?format=api", "username": "jow", "first_name": "Jo-Philipp", "last_name": "Wich", "email": "jow@openwrt.org" }, "mbox": "http://patchwork.ozlabs.org/project/lede/patch/1490009989-29321-2-git-send-email-yszhou4tech@gmail.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/740957/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/740957/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Received": [ "from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3vmvC33cQwz9s1y\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 20 Mar 2017 22:40:31 +1100 (AEDT)", "from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1cpvfi-00073K-EX; Mon, 20 Mar 2017 11:40:22 +0000", "from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1cpvfW-0005d2-9p\n\tfor lede-dev@lists.infradead.org; Mon, 20 Mar 2017 11:40:13 +0000", "by mail-pg0-x241.google.com with SMTP id 79so10797291pgf.0\n\tfor <lede-dev@lists.infradead.org>;\n\tMon, 20 Mar 2017 04:39:49 -0700 (PDT)", "from titan.office.mos ([103.29.140.57])\n\tby smtp.gmail.com with ESMTPSA id\n\ta77sm32791902pfl.91.2017.03.20.04.39.47\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tMon, 20 Mar 2017 04:39:48 -0700 (PDT)" ], "Authentication-Results": "ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"rntKiTXC\"; \n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"KkJ8mmRF\"; dkim-atps=neutral", "DKIM-Signature": [ "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References:\n\tIn-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=ZyjzEjEnYTGbjDFdYsV0KJhn8bLmZTVKr3Ds9gZyeTI=;\n\tb=rntKiTXCGqkrRy\n\tFPxk+iyy/2GSnwxVpntDhbQRyCFdB3EaalQzwSqaOAfdo3FPfCLSDcIbA6Hc51JajDQsvWGJ21NiC\n\tlycWShOEd3vfdXWxfrxvaFMgpNmkcHMo4tteIB5lte5oGhElI8KUgDRQT2cD4wwpmdDhPacz5MnmF\n\ti3JfvWg2o5Ykhz+SjnpPeqGP0skU9amoEvWc3NkWpLajd+8bzBFi4M0dn4D5mm5nE/JEXKTzYrbHX\n\tuqsIiAq2oOHazgKX8ZhueegNosZ2lv839KVixk+f4BmwatW0hHl3EJaPl8RIu6emj0ThhVDE/pyyJ\n\tB2SNsvxRsvm/pNA56IjQ==;", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=iiXATO9vZcqbseAP0dNtg6ud3QO0KPBD50EMBScHijA=;\n\tb=KkJ8mmRFWF8MyMCgCdXG2Xz2ZnC+fOjKymks9+zK4ztRCdJMh2iVT4NbG8hG02ehP7\n\txECkdkeyBVFfBseE+THP1StGwQLrHKrufXlM1QfWOP8d9lyAOKzGu7/fTkUhYz0lwqWU\n\t8nm+yEyTLV9b7OzDuvKM9iZucyBBiQ74CkZAC6emlikcRhfuR/33PvmJAoNe9/K15M+F\n\tEiGhcIMUwj1yPnGYNcs6S9KAvpTpaAql+Rj1fIWnRLf/Z9bYsIOGGSnKbbWA6Q6ngjb6\n\tI2OV5jyk7QKCakWfj25/wOkoKRYtTnBjluWxfqdu2dMqUCN7X7ttQ2yJylODhrVkXDrA\n\tzAhg==" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=iiXATO9vZcqbseAP0dNtg6ud3QO0KPBD50EMBScHijA=;\n\tb=Zo0vPU/wp4jHjlsFD/PKJSn6cwTidQmar08EcaC1/1fUsdI7F3twPxGEGBYl/LgA1Q\n\teYfk9b8eOse7cDcBSi/rcs58q6eQFqopeewgaywO/vKIQYADa8KaUyMDN4hXFdceEFCr\n\tOZuGzAbFPN8/IEBNyioSmV6BYq+hkdRgYlVlnHo22O9KUGLHfXRvVFEQM20FTeEFt0b9\n\t7qccQJXSpfjUONKQvXPMYOS9CoarEnzqSo9C2uLAFbY64HQFWl3aqLk1naHzv4sXM7kU\n\tSHMsjgmkZJdUuYAV5Ta9YwkSPswl9MHiE5EZfcIgATSPa8YI6Di6ZEJjSuwe/+QR2RL9\n\tZS/Q==", "X-Gm-Message-State": "AFeK/H3TYDA1gIlR20NZBfzYZLk9YmNtHdFPWZg1CQBqqe90bP9adfdo+R+QgvX2IFJDvw==", "X-Received": "by 10.98.129.194 with SMTP id\n\tt185mr32882920pfd.137.1490009989140; \n\tMon, 20 Mar 2017 04:39:49 -0700 (PDT)", "From": "Yousong Zhou <yszhou4tech@gmail.com>", "To": "jo@mein.io", "Date": "Mon, 20 Mar 2017 19:39:49 +0800", "Message-Id": "<1490009989-29321-2-git-send-email-yszhou4tech@gmail.com>", "X-Mailer": "git-send-email 2.6.4", "In-Reply-To": "<1490009989-29321-1-git-send-email-yszhou4tech@gmail.com>", "References": "<1490009989-29321-1-git-send-email-yszhou4tech@gmail.com>", "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ", "X-CRM114-CacheID": "sfid-20170320_044010_540336_5D9D31BA ", "X-CRM114-Status": "GOOD ( 23.60 )", "X-Spam-Score": "-2.0 (--)", "X-Spam-Report": "SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details: (-2.0 points)\n\tpts rule name description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,\n\tno\n\ttrust [2607:f8b0:400e:c05:0:0:0:241 listed in] [list.dnswl.org]\n\t-0.0 SPF_PASS SPF: sender matches SPF record\n\t0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\n\tprovider (yszhou4tech[at]gmail.com)\n\t-1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]\n\t0.1 DKIM_SIGNED Message has a DKIM or DK signature,\n\tnot necessarily valid\n\t-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature\n\t-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from\n\tauthor's domain", "Subject": "[LEDE-DEV] [PATCH opkg-lede 2/2] pkg: alternatives support", "X-BeenThere": "lede-dev@lists.infradead.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<lede-dev.lists.infradead.org>", "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/lede-dev>,\n\t<mailto:lede-dev-request@lists.infradead.org?subject=unsubscribe>", "List-Archive": "<http://lists.infradead.org/pipermail/lede-dev/>", "List-Post": "<mailto:lede-dev@lists.infradead.org>", "List-Help": "<mailto:lede-dev-request@lists.infradead.org?subject=help>", "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/lede-dev>,\n\t<mailto:lede-dev-request@lists.infradead.org?subject=subscribe>", "Cc": "Yousong Zhou <yszhou4tech@gmail.com>, lede-dev@lists.infradead.org", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Sender": "\"Lede-dev\" <lede-dev-bounces@lists.infradead.org>", "Errors-To": "lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org" }, "content": "It's a list of specs specs of the following form seprated by commas to describe\nalternatives provided by the package\n\n <prio>:<path>:<altpath>\n\n<path> will be a symbolic link to <altpath> of the highest <prio>\n\nSize comparison on x86_64 after the change\n\n function old new delta\n pkg_alternatives_update - 587 +587\n pkg_parse_line 2101 2609 +522\n .rodata 24594 24738 +144\n pkg_formatted_field 2385 2528 +143\n pkg_deinit 427 486 +59\n pkg_print_status 264 280 +16\n opkg_configure 59 69 +10\n xreadlink 120 128 +8\n opkg_remove_pkg 1079 1087 +8\n ------------------------------------------------------------------------------\n (add/remove: 2/0 grow/shrink: 8/0 up/down: 1483/0) Total: 1497 bytes\n\nSigned-off-by: Yousong Zhou <yszhou4tech@gmail.com>\n---\n libopkg/CMakeLists.txt | 2 +-\n libopkg/opkg_configure.c | 3 ++\n libopkg/opkg_remove.c | 2 +\n libopkg/pkg.c | 32 ++++++++++++-\n libopkg/pkg.h | 19 ++++++++\n libopkg/pkg_alternatives.c | 113 +++++++++++++++++++++++++++++++++++++++++++++\n libopkg/pkg_alternatives.h | 23 +++++++++\n libopkg/pkg_parse.c | 81 +++++++++++++++++++++++++++++++-\n libopkg/pkg_parse.h | 53 ++++++++++-----------\n 9 files changed, 299 insertions(+), 29 deletions(-)\n create mode 100644 libopkg/pkg_alternatives.c\n create mode 100644 libopkg/pkg_alternatives.h", "diff": "diff --git a/libopkg/CMakeLists.txt b/libopkg/CMakeLists.txt\nindex 637dadb..1b2a949 100644\n--- a/libopkg/CMakeLists.txt\n+++ b/libopkg/CMakeLists.txt\n@@ -9,7 +9,7 @@ ADD_LIBRARY(opkg STATIC\n \tactive_list.c conffile.c conffile_list.c file_util.c hash_table.c\n \tnv_pair.c nv_pair_list.c opkg.c opkg_cmd.c opkg_conf.c opkg_configure.c\n \topkg_download.c opkg_install.c opkg_message.c opkg_remove.c\n-\topkg_upgrade.c opkg_utils.c parse_util.c pkg.c pkg_depends.c pkg_dest.c\n+\topkg_upgrade.c opkg_utils.c parse_util.c pkg.c pkg_alternatives.c pkg_depends.c pkg_dest.c\n \tpkg_dest_list.c pkg_extract.c pkg_hash.c pkg_parse.c pkg_src.c\n \tpkg_src_list.c pkg_vec.c sha256.c sprintf_alloc.c str_list.c\n \tvoid_list.c xregex.c xsystem.c\ndiff --git a/libopkg/opkg_configure.c b/libopkg/opkg_configure.c\nindex dc05f1e..a043c52 100644\n--- a/libopkg/opkg_configure.c\n+++ b/libopkg/opkg_configure.c\n@@ -21,6 +21,7 @@\n #include \"opkg_configure.h\"\n #include \"opkg_message.h\"\n #include \"opkg_cmd.h\"\n+#include \"pkg_alternatives.h\"\n \n int opkg_configure(pkg_t * pkg)\n {\n@@ -38,5 +39,7 @@ int opkg_configure(pkg_t * pkg)\n \t\treturn err;\n \t}\n \n+\tpkg_alternatives_update(pkg);\n+\n \treturn 0;\n }\ndiff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c\nindex 694c3f3..96ca558 100644\n--- a/libopkg/opkg_remove.c\n+++ b/libopkg/opkg_remove.c\n@@ -22,6 +22,7 @@\n #include \"opkg_message.h\"\n #include \"opkg_remove.h\"\n #include \"opkg_cmd.h\"\n+#include \"pkg_alternatives.h\"\n #include \"file_util.h\"\n #include \"sprintf_alloc.h\"\n #include \"libbb/libbb.h\"\n@@ -312,6 +313,7 @@ int opkg_remove_pkg(pkg_t * pkg, int from_upgrade)\n \n \tremove_maintainer_scripts(pkg);\n \tpkg->state_status = SS_NOT_INSTALLED;\n+\tpkg_alternatives_update(pkg);\n \n \tif (parent_pkg)\n \t\tparent_pkg->state_status = SS_NOT_INSTALLED;\ndiff --git a/libopkg/pkg.c b/libopkg/pkg.c\nindex c0de884..8b873bd 100644\n--- a/libopkg/pkg.c\n+++ b/libopkg/pkg.c\n@@ -321,6 +321,20 @@ void pkg_deinit(pkg_t * pkg)\n \n \t\t\tpkg_set_ptr(pkg, blob_id(cur), NULL);\n \t\t\tbreak;\n+\t\tcase PKG_ALTERNATIVES:\n+\t\t\tptr = pkg_get_ptr(pkg, blob_id(cur));\n+\n+\t\t\tif (ptr) {\n+\t\t\t\tstruct pkg_alternatives *pkg_alts = ptr;\n+\n+\t\t\t\twhile (pkg_alts->nalts)\n+\t\t\t\t\tfree(pkg_alts->alts[--pkg_alts->nalts]);\n+\t\t\t\tfree(pkg_alts->alts);\n+\t\t\t\tfree(pkg_alts);\n+\t\t\t}\n+\n+\t\t\tpkg_set_ptr(pkg, blob_id(cur), NULL);\n+\t\t\tbreak;\n \t\t}\n \t}\n \n@@ -636,7 +650,22 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)\n \tswitch (field[0]) {\n \tcase 'a':\n \tcase 'A':\n-\t\tif (strcasecmp(field, \"Architecture\") == 0) {\n+\t\tif (strcasecmp(field, \"Alternatives\") == 0) {\n+\t\t\tstruct pkg_alternatives *pkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);\n+\n+\t\t\tif (pkg_alts && pkg_alts->nalts > 0) {\n+\t\t\t\tint i;\n+\t\t\t\tstruct pkg_alternative *alt;\n+\n+\t\t\t\talt = pkg_alts->alts[0];\n+\t\t\t\tfprintf(fp, \"Alternatives: %d:%s:%s\", alt->prio, alt->path, alt->altpath);\n+\t\t\t\tfor (i = 1; i < pkg_alts->nalts; i++) {\n+\t\t\t\t\talt = pkg_alts->alts[i];\n+\t\t\t\t\tfprintf(fp, \", %d:%s:%s\", alt->prio, alt->path, alt->altpath);\n+\t\t\t\t}\n+\t\t\t\tfputs(\"\\n\", fp);\n+\t\t\t}\n+\t\t} else if (strcasecmp(field, \"Architecture\") == 0) {\n \t\t\tp = pkg_get_architecture(pkg);\n \t\t\tif (p) {\n \t\t\t\tfprintf(fp, \"Architecture: %s\\n\",\n@@ -938,6 +967,7 @@ void pkg_print_status(pkg_t * pkg, FILE * file)\n \tpkg_formatted_field(file, pkg, \"Conffiles\");\n \tpkg_formatted_field(file, pkg, \"Installed-Time\");\n \tpkg_formatted_field(file, pkg, \"Auto-Installed\");\n+\tpkg_formatted_field(file, pkg, \"Alternatives\");\n \tfputs(\"\\n\", file);\n }\n \ndiff --git a/libopkg/pkg.h b/libopkg/pkg.h\nindex cf405b1..600fc9e 100644\n--- a/libopkg/pkg.h\n+++ b/libopkg/pkg.h\n@@ -100,6 +100,7 @@ enum pkg_fields {\n \tPKG_DEPENDS,\n \tPKG_CONFLICTS,\n \tPKG_CONFFILES,\n+\tPKG_ALTERNATIVES,\n };\n \n struct abstract_pkg {\n@@ -118,6 +119,24 @@ struct abstract_pkg {\n \n #include \"pkg_depends.h\"\n \n+enum pkg_alternative_field {\n+\tPAF_PRIO,\n+\tPAF_PATH,\n+\tPAF_ALTPATH,\n+\t__PAF_MAX,\n+};\n+\n+struct pkg_alternative {\n+\tint prio;\n+\tchar *path;\n+\tchar *altpath;\n+};\n+\n+struct pkg_alternatives {\n+\tint nalts;\n+\tstruct pkg_alternative **alts;\n+};\n+\n /* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:\n \n The 3 version fields should go into a single version struct. (This\ndiff --git a/libopkg/pkg_alternatives.c b/libopkg/pkg_alternatives.c\nnew file mode 100644\nindex 0000000..66b64de\n--- /dev/null\n+++ b/libopkg/pkg_alternatives.c\n@@ -0,0 +1,113 @@\n+/* pkg_alternatives.c - the opkg package management system\n+\n+ Copyright (C) 2017 Yousong Zhou\n+\n+ This program is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU General Public License as\n+ published by the Free Software Foundation; either version 2, or (at\n+ your option) any later version.\n+\n+ This program is distributed in the hope that it will be useful, but\n+ WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ General Public License for more details.\n+*/\n+\n+#include <stdio.h>\n+#include <sys/types.h>\t\t/* stat */\n+#include <sys/stat.h>\n+#include <unistd.h>\n+\n+#include \"libbb/libbb.h\"\n+#include \"opkg_message.h\"\n+#include \"pkg.h\"\n+#include \"pkg_hash.h\"\n+#include \"pkg_alternatives.h\"\n+#include \"sprintf_alloc.h\"\n+\n+static int pkg_alternatives_update_path(pkg_t *pkg, const pkg_vec_t *installed, const char *path)\n+{\n+\tstruct pkg_alternatives *pkg_alts;\n+\tstruct pkg_alternative *the_alt = NULL;\n+\tpkg_t *the_pkg = pkg;\n+\tint i, j;\n+\tint r;\n+\tchar *path_in_dest;\n+\n+\tfor (i = 0; i < installed->len; i++) {\n+\t\tpkg_t *pkg = installed->pkgs[i];\n+\t\tpkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);\n+\t\tif (!pkg_alts)\n+\t\t\tcontinue;\n+\n+\t\tfor (j = 0; j < pkg_alts->nalts; j++) {\n+\t\t\tstruct pkg_alternative *alt = pkg_alts->alts[j];\n+\n+\t\t\tif (strcmp(path, alt->path))\n+\t\t\t\tcontinue;\n+\t\t\tif (!the_alt || the_alt->prio < alt->prio) {\n+\t\t\t\tthe_pkg = pkg;\n+\t\t\t\tthe_alt = alt;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* path is assumed to be an absolute one */\n+\tsprintf_alloc(&path_in_dest, \"%s%s\", the_pkg->dest->root_dir, &path[1]);\n+\tif (!path_in_dest)\n+\t\treturn -1;\n+\n+\tif (the_alt) {\n+\t\tstruct stat sb;\n+\n+\t\tr = lstat(path_in_dest, &sb);\n+\t\tif (!r) {\n+\t\t\tchar *realpath;\n+\n+\t\t\tif (!S_ISLNK(sb.st_mode)) {\n+\t\t\t\topkg_msg(ERROR, \"%s exists but is not a symlink\\n\", path_in_dest);\n+\t\t\t\tr = -1;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\trealpath = xreadlink(path_in_dest);\n+\t\t\tif (realpath && strcmp(realpath, the_alt->altpath))\n+\t\t\t\tunlink(path_in_dest);\n+\t\t\tfree(realpath);\n+\t\t} else if (errno != ENOENT) {\n+\t\t\tgoto out;\n+\t\t}\n+\t\tr = symlink(the_alt->altpath, path_in_dest);\n+\t\tif (r)\n+\t\t\topkg_msg(INFO, \"failed symlinking %s -> %s\\n\", path_in_dest, the_alt->altpath);\n+\t} else {\n+\t\tunlink(path_in_dest);\n+\t\tr = 0;\n+\t}\n+\n+out:\n+\tfree(path_in_dest);\n+\treturn r;\n+}\n+\n+int pkg_alternatives_update(pkg_t * pkg)\n+{\n+\tint r = 0;\n+\tint i;\n+\tstruct pkg_alternatives *pkg_alts;\n+\tstruct pkg_alternative *alt = NULL;\n+\tpkg_vec_t *installed;\n+\n+\tpkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);\n+\tif (!pkg_alts)\n+\t\treturn 0;\n+\n+\tinstalled = pkg_vec_alloc();\n+\tpkg_hash_fetch_all_installed(installed);\n+\tfor (i = 0; i < pkg_alts->nalts; i++) {\n+\t\talt = pkg_alts->alts[i];\n+\t\tr |= pkg_alternatives_update_path(pkg, installed, alt->path);\n+\t}\n+\tpkg_vec_free(installed);\n+\n+\treturn r;\n+}\ndiff --git a/libopkg/pkg_alternatives.h b/libopkg/pkg_alternatives.h\nnew file mode 100644\nindex 0000000..25a5fba\n--- /dev/null\n+++ b/libopkg/pkg_alternatives.h\n@@ -0,0 +1,23 @@\n+/* pkg_alternatives.c - the opkg package management system\n+\n+ Copyright (C) 2017 Yousong Zhou\n+\n+ This program is free software; you can redistribute it and/or\n+ modify it under the terms of the GNU General Public License as\n+ published by the Free Software Foundation; either version 2, or (at\n+ your option) any later version.\n+\n+ This program is distributed in the hope that it will be useful, but\n+ WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ General Public License for more details.\n+*/\n+\n+#ifndef OPKG_ALTERNATIVES_H\n+#define OPKG_ALTERNATIVES_H\n+\n+#include \"pkg.h\"\n+\n+int pkg_alternatives_update(pkg_t * pkg);\n+\n+#endif\ndiff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c\nindex 121f147..d35770c 100644\n--- a/libopkg/pkg_parse.c\n+++ b/libopkg/pkg_parse.c\n@@ -112,6 +112,83 @@ static char *parse_architecture(pkg_t *pkg, const char *str)\n \treturn pkg_set_architecture(pkg, s, e - s);\n }\n \n+static void parse_alternatives(pkg_t *pkg, char *list)\n+{\n+\tchar *item, *tok;\n+\tstruct pkg_alternatives *pkg_alts;\n+\tstruct pkg_alternative **alts;\n+\tint nalts;\n+\n+\tpkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);\n+\tif (!pkg_alts) {\n+\t\tnalts = 0;\n+\t\talts = NULL;\n+\t} else {\n+\t\tnalts = pkg_alts->nalts;\n+\t\talts = pkg_alts->alts;\n+\t}\n+\n+\tfor (item = strtok_r(list, \",\", &tok);\n+\t\t\titem;\n+\t\t\titem = strtok_r(NULL, \",\", &tok)) {\n+\t\tenum pkg_alternative_field i;\n+\t\tchar *val, *tok1;\n+\t\t/* the assignment was intended to quash the -Wmaybe-uninitialized warnings */\n+\t\tint prio = prio;\n+\t\tchar *path = path, *altpath = altpath;\n+\n+\t\tfor (i = PAF_PRIO, val = strtok_r(item, \":\", &tok1);\n+\t\t\t\tval && i < __PAF_MAX;\n+\t\t\t\tval = strtok_r(NULL, \":\", &tok1), i++) {\n+\t\t\tswitch (i) {\n+\t\t\t\tcase PAF_PRIO:\n+\t\t\t\t\tprio = atoi(val);\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase PAF_PATH:\n+\t\t\t\t\tpath = val;\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase PAF_ALTPATH:\n+\t\t\t\t\taltpath = val;\n+\t\t\t\t\tbreak;\n+\t\t\t\tdefault:\n+\t\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tif (!val && i == __PAF_MAX) {\n+\t\t\tchar *_path, *_altpath;\n+\t\t\tstruct pkg_alternative *alt;\n+\n+\t\t\t/*\n+\t\t\t * - path must be absolute\n+\t\t\t * - altpath must be non-empty\n+\t\t\t */\n+\t\t\tif (path[0] != '/' || !altpath[0])\n+\t\t\t\tcontinue;\n+\n+\t\t\talt = calloc_a(sizeof(*alt),\n+\t\t\t\t\t&_path, strlen(path) + 1,\n+\t\t\t\t\t&_altpath, strlen(altpath) + 1);\n+\t\t\tif (!alt)\n+\t\t\t\tcontinue;\n+\t\t\tstrcpy(_path, path);\n+\t\t\tstrcpy(_altpath, altpath);\n+\t\t\talt->prio = prio;\n+\t\t\talt->path = _path;\n+\t\t\talt->altpath = _altpath;\n+\t\t\talts = xrealloc(alts, sizeof(*alts) * (nalts + 1));\n+\t\t\talts[nalts++] = alt;\n+\t\t}\n+\t}\n+\n+\tif (nalts > 0) {\n+\t\tif (!pkg_alts)\n+\t\t\tpkg_alts = xmalloc(sizeof(*pkg_alts));\n+\t\tpkg_alts->nalts = nalts;\n+\t\tpkg_alts->alts = alts;\n+\t\tpkg_set_ptr(pkg, PKG_ALTERNATIVES, pkg_alts);\n+\t}\n+}\n+\n int pkg_parse_line(void *ptr, char *line, uint mask)\n {\n \tpkg_t *pkg = (pkg_t *) ptr;\n@@ -131,7 +208,9 @@ int pkg_parse_line(void *ptr, char *line, uint mask)\n \n \tswitch (*line) {\n \tcase 'A':\n-\t\tif ((mask & PFM_ARCHITECTURE) && is_field(\"Architecture\", line))\n+\t\tif ((mask & PFM_ALTERNATIVES) && is_field(\"Alternatives\", line))\n+\t\t\tparse_alternatives(pkg, line + strlen(\"Alternatives\") + 1);\n+\t\telse if ((mask & PFM_ARCHITECTURE) && is_field(\"Architecture\", line))\n \t\t\tparse_architecture(pkg, line + strlen(\"Architecture\") + 1);\n \t\telse if ((mask & PFM_AUTO_INSTALLED)\n \t\t\t && is_field(\"Auto-Installed\", line)) {\ndiff --git a/libopkg/pkg_parse.h b/libopkg/pkg_parse.h\nindex ac8d7c0..d1f901a 100644\n--- a/libopkg/pkg_parse.h\n+++ b/libopkg/pkg_parse.h\n@@ -27,32 +27,33 @@ int pkg_parse_line(void *ptr, char *line, uint mask);\n #define EXCESSIVE_LINE_LEN\t(4096 << 8)\n \n /* package field mask */\n-#define PFM_ARCHITECTURE\t(1 << 1)\n-#define PFM_AUTO_INSTALLED\t(1 << 2)\n-#define PFM_CONFFILES\t\t(1 << 3)\n-#define PFM_CONFLICTS\t\t(1 << 4)\n-#define PFM_DESCRIPTION\t\t(1 << 5)\n-#define PFM_DEPENDS\t\t(1 << 6)\n-#define PFM_ESSENTIAL\t\t(1 << 7)\n-#define PFM_FILENAME\t\t(1 << 8)\n-#define PFM_INSTALLED_SIZE\t(1 << 9)\n-#define PFM_INSTALLED_TIME\t(1 << 10)\n-#define PFM_MD5SUM\t\t(1 << 11)\n-#define PFM_MAINTAINER\t\t(1 << 12)\n-#define PFM_PACKAGE\t\t(1 << 13)\n-#define PFM_PRIORITY\t\t(1 << 14)\n-#define PFM_PROVIDES\t\t(1 << 15)\n-#define PFM_PRE_DEPENDS\t\t(1 << 16)\n-#define PFM_RECOMMENDS\t\t(1 << 17)\n-#define PFM_REPLACES\t\t(1 << 18)\n-#define PFM_SECTION\t\t(1 << 19)\n-#define PFM_SHA256SUM\t\t(1 << 20)\n-#define PFM_SIZE\t\t(1 << 21)\n-#define PFM_SOURCE\t\t(1 << 22)\n-#define PFM_STATUS\t\t(1 << 23)\n-#define PFM_SUGGESTS\t\t(1 << 24)\n-#define PFM_TAGS\t\t(1 << 25)\n-#define PFM_VERSION\t\t(1 << 26)\n+#define PFM_ALTERNATIVES\t(1 << 1)\n+#define PFM_ARCHITECTURE\t(1 << 2)\n+#define PFM_AUTO_INSTALLED\t(1 << 3)\n+#define PFM_CONFFILES\t\t(1 << 4)\n+#define PFM_CONFLICTS\t\t(1 << 5)\n+#define PFM_DESCRIPTION\t\t(1 << 6)\n+#define PFM_DEPENDS\t\t(1 << 7)\n+#define PFM_ESSENTIAL\t\t(1 << 8)\n+#define PFM_FILENAME\t\t(1 << 9)\n+#define PFM_INSTALLED_SIZE\t(1 << 10)\n+#define PFM_INSTALLED_TIME\t(1 << 11)\n+#define PFM_MD5SUM\t\t(1 << 12)\n+#define PFM_MAINTAINER\t\t(1 << 13)\n+#define PFM_PACKAGE\t\t(1 << 14)\n+#define PFM_PRIORITY\t\t(1 << 15)\n+#define PFM_PROVIDES\t\t(1 << 16)\n+#define PFM_PRE_DEPENDS\t\t(1 << 17)\n+#define PFM_RECOMMENDS\t\t(1 << 18)\n+#define PFM_REPLACES\t\t(1 << 19)\n+#define PFM_SECTION\t\t(1 << 20)\n+#define PFM_SHA256SUM\t\t(1 << 21)\n+#define PFM_SIZE\t\t(1 << 22)\n+#define PFM_SOURCE\t\t(1 << 23)\n+#define PFM_STATUS\t\t(1 << 24)\n+#define PFM_SUGGESTS\t\t(1 << 25)\n+#define PFM_TAGS\t\t(1 << 26)\n+#define PFM_VERSION\t\t(1 << 27)\n \n #define PFM_ALL\t(~(uint)0)\n \n", "prefixes": [ "LEDE-DEV", "opkg-lede", "2/2" ] }