Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/prefix:master commit in: scripts/rsync-generation/
Date: Wed, 29 Nov 2017 16:46:14
Message-Id: 1511973774.191df7d69bc652b5e7899d44934fea0de05aa53d.grobian@gentoo
1 commit: 191df7d69bc652b5e7899d44934fea0de05aa53d
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Wed Nov 29 16:42:54 2017 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 29 16:42:54 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=191df7d6
7
8 hashgen: generate GLEP 74 top level Manifest
9
10 scripts/rsync-generation/hashgen.c | 56 ++++++++++++++++++++++++++++++++++----
11 1 file changed, 50 insertions(+), 6 deletions(-)
12
13 diff --git a/scripts/rsync-generation/hashgen.c b/scripts/rsync-generation/hashgen.c
14 index 034ea7f170..4180665e0f 100644
15 --- a/scripts/rsync-generation/hashgen.c
16 +++ b/scripts/rsync-generation/hashgen.c
17 @@ -4,6 +4,7 @@
18 #include <strings.h>
19 #include <ctype.h>
20 #include <dirent.h>
21 +#include <time.h>
22 #include <errno.h>
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 @@ -95,7 +96,7 @@ write_hashes(
26 #pragma omp section
27 {
28 if (hashes & HASH_BLAKE2B)
29 - blake2b_update(&bl2b, data, len);
30 + blake2b_update(&bl2b, (unsigned char *)data, len);
31 }
32 }
33 }
34 @@ -152,7 +153,7 @@ write_hashes(
35 len += snprintf(data + len, sizeof(data) - len, "\n");
36
37 if (m != NULL)
38 - fwrite(data, 1, len, m);
39 + fwrite(data, len, 1, m);
40 if (gm != NULL)
41 gzwrite(gm, data, len);
42 }
43 @@ -202,7 +203,7 @@ parse_layout_conf(const char *path)
44
45 /* read file, examine lines after encountering a newline, that is,
46 * if the file doesn't end with a newline, the final bit is ignored */
47 - while (sz = fread(buf + len, 1, sizeof(buf) - len, f) > 0) {
48 + while ((sz = fread(buf + len, 1, sizeof(buf) - len, f)) > 0) {
49 len += sz;
50 last_nl = NULL;
51 for (p = buf; p - buf < len; p++) {
52 @@ -256,6 +257,7 @@ parse_layout_conf(const char *path)
53
54 static char *str_manifest = "Manifest";
55 static char *str_manifest_gz = "Manifest.gz";
56 +static char *str_manifest_files_gz = "Manifest.files.gz";
57 static char *
58 process_dir(const char *dir)
59 {
60 @@ -296,10 +298,12 @@ process_dir(const char *dir)
61 /* recurse into subdirs */
62 if ((d = opendir(dir)) != NULL) {
63 struct stat s;
64 + char *my_manifest =
65 + global_manifest ? str_manifest_files_gz : str_manifest_gz;
66
67 /* open up a gzipped Manifest to keep the hashes of the
68 * Manifests in the subdirs */
69 - snprintf(manifest, sizeof(manifest), "%s/%s", dir, str_manifest_gz);
70 + snprintf(manifest, sizeof(manifest), "%s/%s", dir, my_manifest);
71 if ((mf = gzopen(manifest, "wb9")) == NULL) {
72 fprintf(stderr, "failed to open file '%s' for writing: %s\n",
73 manifest, strerror(errno));
74 @@ -309,7 +313,7 @@ process_dir(const char *dir)
75 while ((e = readdir(d)) != NULL) {
76 if (e->d_name[0] == '.')
77 continue;
78 - if (strcmp(e->d_name, str_manifest_gz) == 0)
79 + if (strcmp(e->d_name, my_manifest) == 0)
80 continue;
81 snprintf(path, sizeof(path), "%s/%s", dir, e->d_name);
82 if (!stat(path, &s)) {
83 @@ -328,7 +332,47 @@ process_dir(const char *dir)
84 }
85 closedir(d);
86
87 - gzclose(mf);
88 + if (global_manifest) {
89 + char globmanifest[8192];
90 + char buf[2048];
91 + size_t len;
92 + FILE *m;
93 + time_t rtime;
94 +
95 + len = snprintf(buf, sizeof(buf),
96 + "IGNORE distfiles\n"
97 + "IGNORE local\n"
98 + "IGNORE lost+found\n"
99 + "IGNORE packages\n");
100 + gzwrite(mf, buf, len);
101 + gzclose(mf);
102 +
103 + /* create global Manifest */
104 + snprintf(globmanifest, sizeof(globmanifest),
105 + "%s/%s", dir, str_manifest);
106 + if ((m = fopen(globmanifest, "w")) == NULL) {
107 + fprintf(stderr, "failed to open file '%s' "
108 + "for writing: %s\n",
109 + globmanifest, strerror(errno));
110 + return NULL;
111 + }
112 +
113 + write_hashes(dir, my_manifest, "MANIFEST", m, NULL);
114 + time(&rtime);
115 + len = strftime(buf, sizeof(buf),
116 + "TIMESTAMP %Y-%m-%dT%H:%M:%SZ\n", gmtime(&rtime));
117 + fwrite(buf, len, 1, m);
118 + fflush(m);
119 + fclose(m);
120 +
121 + if (tv[0].tv_sec != 0) {
122 + /* restore dir mtime, and set Manifest mtime to match it */
123 + utimes(globmanifest, tv);
124 + }
125 + } else {
126 + gzclose(mf);
127 + }
128 +
129 if (tv[0].tv_sec != 0) {
130 /* restore dir mtime, and set Manifest mtime to match it */
131 utimes(manifest, tv);