get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/13577/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13577,
    "url": "http://patches.dpdk.org/api/patches/13577/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1465830465-30058-6-git-send-email-viktorin@rehivetech.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1465830465-30058-6-git-send-email-viktorin@rehivetech.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1465830465-30058-6-git-send-email-viktorin@rehivetech.com",
    "date": "2016-06-13T15:07:40",
    "name": "[dpdk-dev,v5,05/10] app/test: support resources archived by tar",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "e0d428bf6b165e1f124ca46c7063eb8687c23fcd",
    "submitter": {
        "id": 292,
        "url": "http://patches.dpdk.org/api/people/292/?format=api",
        "name": "Jan Viktorin",
        "email": "viktorin@rehivetech.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1465830465-30058-6-git-send-email-viktorin@rehivetech.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/13577/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/13577/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 7D9CC58C5;\n\tMon, 13 Jun 2016 17:13:02 +0200 (CEST)",
            "from wes1-so1.wedos.net (wes1-so1.wedos.net [46.28.106.15])\n\tby dpdk.org (Postfix) with ESMTP id 1128E5593\n\tfor <dev@dpdk.org>; Mon, 13 Jun 2016 17:12:56 +0200 (CEST)",
            "from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz\n\t[147.229.13.147])\n\tby wes1-so1.wedos.net (Postfix) with ESMTPSA id 3rSx9M6S0CzCD2;\n\tMon, 13 Jun 2016 17:12:55 +0200 (CEST)"
        ],
        "From": "Jan Viktorin <viktorin@rehivetech.com>",
        "To": "dev@dpdk.org",
        "Cc": "Jan Viktorin <viktorin@rehivetech.com>,\n\tThomas Monjalon <thomas.monjalon@6wind.com>,\n\tDavid Marchand <david.marchand@6wind.com>,\n\tBruce Richardson <bruce.richardson@intel.com>",
        "Date": "Mon, 13 Jun 2016 17:07:40 +0200",
        "Message-Id": "<1465830465-30058-6-git-send-email-viktorin@rehivetech.com>",
        "X-Mailer": "git-send-email 2.8.0",
        "In-Reply-To": [
            "<1465830465-30058-1-git-send-email-viktorin@rehivetech.com>",
            "<1465805550-30640-1-git-send-email-viktorin@rehivetech.com>"
        ],
        "References": [
            "<1465830465-30058-1-git-send-email-viktorin@rehivetech.com>",
            "<1465805550-30640-1-git-send-email-viktorin@rehivetech.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v5 05/10] app/test: support resources archived by\n\ttar",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "When a more complex resource (a file hierarchy) is needed, packing\nevery single file as a single resource would be very ineffective. For\nthat purpose, it is possible to pack the files into a tar archive,\nextract it before test from the resource and finally clean up all the\ncreated files.\n\nThis patch introduces functions resource_untar and resource_rm_by_tar\nto perform those tasks. An example of using those functions is included\nas a test.\n\nA new dependency is required to build the app/test: libarchive.\n\nSigned-off-by: Jan Viktorin <viktorin@rehivetech.com>\n---\nv5:\n* fix archive_read_data_block, more info:\n  https://github.com/libarchive/libarchive/blob/master/examples/untar.c#L205\n  http://markmail.org/message/y4pgi44gqjd4jfuc\n---\n app/test/Makefile        |   9 +++\n app/test/resource.c      | 200 +++++++++++++++++++++++++++++++++++++++++++++++\n app/test/resource.h      |  13 +++\n app/test/test_resource.c |  29 +++++++\n 4 files changed, 251 insertions(+)",
    "diff": "diff --git a/app/test/Makefile b/app/test/Makefile\nindex fe67eee..1cc6258 100644\n--- a/app/test/Makefile\n+++ b/app/test/Makefile\n@@ -51,6 +51,13 @@ $(1).res.o: $(2)\n \t\t/dev/stdin $$@ < $$<\n endef\n \n+define linked_tar_resource\n+$(1).tar: $(2)\n+\ttar -C $$(dir $$<) -cf $$@ $$(notdir $$<)\n+\n+$(call linked_resource,$(1),$(1).tar)\n+endef\n+\n #\n # library name\n #\n@@ -64,6 +71,7 @@ SRCS-y += test.c\n SRCS-y += resource.c\n SRCS-y += test_resource.c\n $(eval $(call linked_resource,test_resource_c,resource.c))\n+$(eval $(call linked_tar_resource,test_resource_tar,test_resource.c))\n SRCS-y += test_pci.c\n SRCS-y += test_prefetch.c\n SRCS-y += test_byteorder.c\n@@ -185,6 +193,7 @@ CFLAGS += $(WERROR_FLAGS)\n CFLAGS += -D_GNU_SOURCE\n \n LDLIBS += -lm\n+LDLIBS += -larchive\n \n # Disable VTA for memcpy test\n ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)\ndiff --git a/app/test/resource.c b/app/test/resource.c\nindex acb63c1..8c42eea 100644\n--- a/app/test/resource.c\n+++ b/app/test/resource.c\n@@ -33,6 +33,8 @@\n \n #include <stdio.h>\n #include <string.h>\n+#include <archive.h>\n+#include <archive_entry.h>\n #include <errno.h>\n #include <sys/queue.h>\n \n@@ -95,6 +97,204 @@ int resource_fwrite_file(const struct resource *r, const char *fname)\n \treturn ret;\n }\n \n+static int do_copy(struct archive *r, struct archive *w)\n+{\n+\tconst void *buf;\n+\tsize_t len;\n+#if ARCHIVE_VERSION_NUMBER >= 3000000\n+\tint64_t off;\n+#else\n+\toff_t off;\n+#endif\n+\tint ret;\n+\n+\twhile (1) {\n+\t\tret = archive_read_data_block(r, &buf, &len, &off);\n+\t\tif (ret == ARCHIVE_RETRY)\n+\t\t\tcontinue;\n+\n+\t\tif (ret == ARCHIVE_EOF)\n+\t\t\treturn 0;\n+\n+\t\tif (ret != ARCHIVE_OK)\n+\t\t\treturn ret;\n+\n+\t\tdo {\n+\t\t\tret = archive_write_data_block(w, buf, len, off);\n+\t\t\tif (ret != ARCHIVE_OK && ret != ARCHIVE_RETRY)\n+\t\t\t\treturn ret;\n+\t\t} while (ret != ARCHIVE_OK);\n+\t}\n+}\n+\n+int resource_untar(const struct resource *res)\n+{\n+\tstruct archive *r;\n+\tstruct archive *w;\n+\tstruct archive_entry *e;\n+\tvoid *p;\n+\tint flags = 0;\n+\tint ret;\n+\n+\tp = malloc(resource_size(res));\n+\tif (p == NULL)\n+\t\trte_panic(\"Failed to malloc %zu B\\n\", resource_size(res));\n+\n+\tmemcpy(p, res->begin, resource_size(res));\n+\n+\tr = archive_read_new();\n+\tif (r == NULL) {\n+\t\tfree(p);\n+\t\treturn -1;\n+\t}\n+\n+\tarchive_read_support_format_all(r);\n+\tarchive_read_support_filter_all(r);\n+\n+\tw = archive_write_disk_new();\n+\tif (w == NULL) {\n+\t\tarchive_read_free(r);\n+\t\tfree(p);\n+\t\treturn -1;\n+\t}\n+\n+\tflags |= ARCHIVE_EXTRACT_PERM;\n+\tflags |= ARCHIVE_EXTRACT_FFLAGS;\n+\tarchive_write_disk_set_options(w, flags);\n+\tarchive_write_disk_set_standard_lookup(w);\n+\n+\tret = archive_read_open_memory(r, p, resource_size(res));\n+\tif (ret != ARCHIVE_OK)\n+\t\tgoto fail;\n+\n+\twhile (1) {\n+\t\tret = archive_read_next_header(r, &e);\n+\t\tif (ret == ARCHIVE_EOF)\n+\t\t\tbreak;\n+\t\tif (ret != ARCHIVE_OK)\n+\t\t\tgoto fail;\n+\n+\t\tret = archive_write_header(w, e);\n+\t\tif (ret == ARCHIVE_EOF)\n+\t\t\tbreak;\n+\t\tif (ret != ARCHIVE_OK)\n+\t\t\tgoto fail;\n+\n+\t\tif (archive_entry_size(e) == 0)\n+\t\t\tcontinue;\n+\n+\t\tret = do_copy(r, w);\n+\t\tif (ret != ARCHIVE_OK)\n+\t\t\tgoto fail;\n+\n+\t\tret = archive_write_finish_entry(w);\n+\t\tif (ret != ARCHIVE_OK)\n+\t\t\tgoto fail;\n+\t}\n+\n+\tarchive_write_free(w);\n+\tarchive_read_free(r);\n+\tfree(p);\n+\treturn 0;\n+\n+fail:\n+\tarchive_write_free(w);\n+\tarchive_read_free(r);\n+\tfree(p);\n+\trte_panic(\"Failed: %s\\n\", archive_error_string(r));\n+\treturn -1;\n+}\n+\n+int resource_rm_by_tar(const struct resource *res)\n+{\n+\tstruct archive *r;\n+\tstruct archive_entry *e;\n+\tvoid *p;\n+\tint try_again = 1;\n+\tint attempts = 0;\n+\tint ret;\n+\n+\tp = malloc(resource_size(res));\n+\tif (p == NULL)\n+\t\trte_panic(\"Failed to malloc %zu B\\n\", resource_size(res));\n+\n+\tmemcpy(p, res->begin, resource_size(res));\n+\n+\t/*\n+\t * If somebody creates a file somewhere inside the extracted TAR\n+\t * hierarchy during a test the resource_rm_by_tar might loop\n+\t * infinitely. We prevent this by adding the attempts counter there.\n+\t * In normal case, max N iteration is done where N is the depth of\n+\t * the file-hierarchy.\n+\t */\n+\twhile (try_again && attempts < 10000) {\n+\t\tr = archive_read_new();\n+\t\tif (r == NULL) {\n+\t\t\tfree(p);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tarchive_read_support_format_all(r);\n+\t\tarchive_read_support_filter_all(r);\n+\n+\t\tret = archive_read_open_memory(r, p, resource_size(res));\n+\t\tif (ret != ARCHIVE_OK) {\n+\t\t\tfprintf(stderr, \"Failed: %s\\n\",\n+\t\t\t\t\tarchive_error_string(r));\n+\t\t\tgoto fail;\n+\t\t}\n+\n+\t\ttry_again = 0;\n+\n+\t\twhile (1) {\n+\t\t\tret = archive_read_next_header(r, &e);\n+\t\t\tif (ret == ARCHIVE_EOF)\n+\t\t\t\tbreak;\n+\t\t\tif (ret != ARCHIVE_OK)\n+\t\t\t\tgoto fail;\n+\n+\t\t\tret = remove(archive_entry_pathname(e));\n+\t\t\tif (ret < 0) {\n+\t\t\t\tswitch (errno) {\n+\t\t\t\tcase ENOTEMPTY:\n+\t\t\t\tcase EEXIST:\n+\t\t\t\t\ttry_again = 1;\n+\t\t\t\t\tbreak;\n+\n+\t\t\t\t/* should not usually happen: */\n+\t\t\t\tcase ENOENT:\n+\t\t\t\tcase ENOTDIR:\n+\t\t\t\tcase EROFS:\n+\t\t\t\t\tattempts += 1;\n+\t\t\t\t\tcontinue;\n+\t\t\t\tdefault:\n+\t\t\t\t\tperror(\"Failed to remove file\");\n+\t\t\t\t\tgoto fail;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\tarchive_read_free(r);\n+\t\tattempts += 1;\n+\t}\n+\n+\tif (attempts >= 10000) {\n+\t\tfprintf(stderr, \"Failed to remove archive\\n\");\n+\t\tfree(p);\n+\t\treturn -1;\n+\t}\n+\n+\tfree(p);\n+\treturn 0;\n+\n+fail:\n+\tarchive_read_free(r);\n+\tfree(p);\n+\n+\trte_panic(\"Failed: %s\\n\", archive_error_string(r));\n+\treturn -1;\n+}\n+\n void resource_register(struct resource *r)\n {\n \tTAILQ_INSERT_TAIL(&resource_list, r, next);\ndiff --git a/app/test/resource.h b/app/test/resource.h\nindex ac9cae6..1e96122 100644\n--- a/app/test/resource.h\n+++ b/app/test/resource.h\n@@ -89,6 +89,19 @@ int resource_fwrite(const struct resource *r, FILE *f);\n int resource_fwrite_file(const struct resource *r, const char *fname);\n \n /**\n+ * Treat the given resource as a tar archive. Extract\n+ * the archive to the current directory.\n+ */\n+int resource_untar(const struct resource *res);\n+\n+/**\n+ * Treat the given resource as a tar archive. Remove\n+ * all files (related to the current directory) listed\n+ * in the tar archive.\n+ */\n+int resource_rm_by_tar(const struct resource *res);\n+\n+/**\n  * Register a resource in the global list of resources.\n  * Not intended for direct use, please check the REGISTER_RESOURCE\n  * macro.\ndiff --git a/app/test/test_resource.c b/app/test/test_resource.c\nindex 3d1bf00..1e85040 100644\n--- a/app/test/test_resource.c\n+++ b/app/test/test_resource.c\n@@ -85,6 +85,32 @@ static int test_resource_c(void)\n \treturn 0;\n }\n \n+REGISTER_LINKED_RESOURCE(test_resource_tar);\n+\n+static int test_resource_tar(void)\n+{\n+\tconst struct resource *r;\n+\tFILE *f;\n+\n+\tr = resource_find(\"test_resource_tar\");\n+\tTEST_ASSERT_NOT_NULL(r, \"No test_resource_tar found\");\n+\tTEST_ASSERT(!strcmp(r->name, \"test_resource_tar\"),\n+\t\t\t\"Found resource %s, expected test_resource_tar\",\n+\t\t\tr->name);\n+\n+\tTEST_ASSERT_SUCCESS(resource_untar(r),\n+\t\t\t\"Failed to to untar %s\", r->name);\n+\n+\tf = fopen(\"test_resource.c\", \"r\");\n+\tTEST_ASSERT_NOT_NULL(f,\n+\t\t\t\"Missing extracted file test_resource.c\");\n+\tfclose(f);\n+\n+\tTEST_ASSERT_SUCCESS(resource_rm_by_tar(r),\n+\t\t\t\"Failed to remove extracted contents of %s\", r->name);\n+\treturn 0;\n+}\n+\n static int test_resource(void)\n {\n \tif (test_resource_dpdk())\n@@ -93,6 +119,9 @@ static int test_resource(void)\n \tif (test_resource_c())\n \t\treturn -1;\n \n+\tif (test_resource_tar())\n+\t\treturn -1;\n+\n \treturn 0;\n }\n \n",
    "prefixes": [
        "dpdk-dev",
        "v5",
        "05/10"
    ]
}