From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 9CD01139084 for ; Wed, 29 Nov 2017 16:46:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E46AFE0BEF; Wed, 29 Nov 2017 16:46:13 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B5C4FE0BEF for ; Wed, 29 Nov 2017 16:46:13 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5DA1933C4EE for ; Wed, 29 Nov 2017 16:46:12 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 24FDAABC8 for ; Wed, 29 Nov 2017 16:46:11 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1511973774.191df7d69bc652b5e7899d44934fea0de05aa53d.grobian@gentoo> Subject: [gentoo-commits] repo/proj/prefix:master commit in: scripts/rsync-generation/ X-VCS-Repository: repo/proj/prefix X-VCS-Files: scripts/rsync-generation/hashgen.c X-VCS-Directories: scripts/rsync-generation/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 191df7d69bc652b5e7899d44934fea0de05aa53d X-VCS-Branch: master Date: Wed, 29 Nov 2017 16:46:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 27d52659-f9f3-4045-aec6-537b2aef1e26 X-Archives-Hash: cf3ff262ccf553a974c6383eff7dfcf3 commit: 191df7d69bc652b5e7899d44934fea0de05aa53d Author: Fabian Groffen gentoo org> AuthorDate: Wed Nov 29 16:42:54 2017 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Wed Nov 29 16:42:54 2017 +0000 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=191df7d6 hashgen: generate GLEP 74 top level Manifest scripts/rsync-generation/hashgen.c | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/scripts/rsync-generation/hashgen.c b/scripts/rsync-generation/hashgen.c index 034ea7f170..4180665e0f 100644 --- a/scripts/rsync-generation/hashgen.c +++ b/scripts/rsync-generation/hashgen.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -95,7 +96,7 @@ write_hashes( #pragma omp section { if (hashes & HASH_BLAKE2B) - blake2b_update(&bl2b, data, len); + blake2b_update(&bl2b, (unsigned char *)data, len); } } } @@ -152,7 +153,7 @@ write_hashes( len += snprintf(data + len, sizeof(data) - len, "\n"); if (m != NULL) - fwrite(data, 1, len, m); + fwrite(data, len, 1, m); if (gm != NULL) gzwrite(gm, data, len); } @@ -202,7 +203,7 @@ parse_layout_conf(const char *path) /* read file, examine lines after encountering a newline, that is, * if the file doesn't end with a newline, the final bit is ignored */ - while (sz = fread(buf + len, 1, sizeof(buf) - len, f) > 0) { + while ((sz = fread(buf + len, 1, sizeof(buf) - len, f)) > 0) { len += sz; last_nl = NULL; for (p = buf; p - buf < len; p++) { @@ -256,6 +257,7 @@ parse_layout_conf(const char *path) static char *str_manifest = "Manifest"; static char *str_manifest_gz = "Manifest.gz"; +static char *str_manifest_files_gz = "Manifest.files.gz"; static char * process_dir(const char *dir) { @@ -296,10 +298,12 @@ process_dir(const char *dir) /* recurse into subdirs */ if ((d = opendir(dir)) != NULL) { struct stat s; + char *my_manifest = + global_manifest ? str_manifest_files_gz : str_manifest_gz; /* open up a gzipped Manifest to keep the hashes of the * Manifests in the subdirs */ - snprintf(manifest, sizeof(manifest), "%s/%s", dir, str_manifest_gz); + snprintf(manifest, sizeof(manifest), "%s/%s", dir, my_manifest); if ((mf = gzopen(manifest, "wb9")) == NULL) { fprintf(stderr, "failed to open file '%s' for writing: %s\n", manifest, strerror(errno)); @@ -309,7 +313,7 @@ process_dir(const char *dir) while ((e = readdir(d)) != NULL) { if (e->d_name[0] == '.') continue; - if (strcmp(e->d_name, str_manifest_gz) == 0) + if (strcmp(e->d_name, my_manifest) == 0) continue; snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); if (!stat(path, &s)) { @@ -328,7 +332,47 @@ process_dir(const char *dir) } closedir(d); - gzclose(mf); + if (global_manifest) { + char globmanifest[8192]; + char buf[2048]; + size_t len; + FILE *m; + time_t rtime; + + len = snprintf(buf, sizeof(buf), + "IGNORE distfiles\n" + "IGNORE local\n" + "IGNORE lost+found\n" + "IGNORE packages\n"); + gzwrite(mf, buf, len); + gzclose(mf); + + /* create global Manifest */ + snprintf(globmanifest, sizeof(globmanifest), + "%s/%s", dir, str_manifest); + if ((m = fopen(globmanifest, "w")) == NULL) { + fprintf(stderr, "failed to open file '%s' " + "for writing: %s\n", + globmanifest, strerror(errno)); + return NULL; + } + + write_hashes(dir, my_manifest, "MANIFEST", m, NULL); + time(&rtime); + len = strftime(buf, sizeof(buf), + "TIMESTAMP %Y-%m-%dT%H:%M:%SZ\n", gmtime(&rtime)); + fwrite(buf, len, 1, m); + fflush(m); + fclose(m); + + if (tv[0].tv_sec != 0) { + /* restore dir mtime, and set Manifest mtime to match it */ + utimes(globmanifest, tv); + } + } else { + gzclose(mf); + } + if (tv[0].tv_sec != 0) { /* restore dir mtime, and set Manifest mtime to match it */ utimes(manifest, tv);