1 |
commit: ec87cd2abce74fe8378b7c9aa9b89cb2ccc5bff7 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Dec 1 13:42:20 2017 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Dec 1 13:42:20 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=ec87cd2a |
7 |
|
8 |
hashgen: don't generate Manifest.gz for all subdirs |
9 |
|
10 |
It turns out the generator can decide where Manifest files are created |
11 |
(e.g. there is no spec). Because gemato is not generating Manifest |
12 |
files in some subdirs (most notably install-qa-check.d) apply a simpler |
13 |
strategy for this, just excluding dirs like metadata from Manifest files |
14 |
in each and every subdir. |
15 |
|
16 |
scripts/rsync-generation/hashgen.c | 105 +++++++++++++++++++++++++++++++------ |
17 |
1 file changed, 90 insertions(+), 15 deletions(-) |
18 |
|
19 |
diff --git a/scripts/rsync-generation/hashgen.c b/scripts/rsync-generation/hashgen.c |
20 |
index 0a00c215f7..78944ba9ee 100644 |
21 |
--- a/scripts/rsync-generation/hashgen.c |
22 |
+++ b/scripts/rsync-generation/hashgen.c |
23 |
@@ -160,6 +160,33 @@ write_hashes( |
24 |
} |
25 |
|
26 |
static char |
27 |
+write_hashes_dir(const char *root, const char *name, gzFile zm) |
28 |
+{ |
29 |
+ char path[8192]; |
30 |
+ DIR *d; |
31 |
+ struct dirent *e; |
32 |
+ |
33 |
+ snprintf(path, sizeof(path), "%s/%s", root, name); |
34 |
+ if ((d = opendir(path)) != NULL) { |
35 |
+ while ((e = readdir(d)) != NULL) { |
36 |
+ /* skip all dotfiles */ |
37 |
+ if (e->d_name[0] == '.') |
38 |
+ continue; |
39 |
+ snprintf(path, sizeof(path), "%s/%s", |
40 |
+ name, e->d_name); |
41 |
+ if (write_hashes_dir(root, path, zm)) |
42 |
+ continue; |
43 |
+ /* regular file */ |
44 |
+ write_hashes(root, path, "DATA", NULL, zm); |
45 |
+ } |
46 |
+ closedir(d); |
47 |
+ return 1; |
48 |
+ } else { |
49 |
+ return 0; |
50 |
+ } |
51 |
+} |
52 |
+ |
53 |
+static char |
54 |
process_files(const char *dir, const char *off, FILE *m) |
55 |
{ |
56 |
char path[8192]; |
57 |
@@ -278,8 +305,14 @@ process_dir(const char *dir) |
58 |
DIR *d; |
59 |
struct dirent *e; |
60 |
char path[8192]; |
61 |
+ const char *p; |
62 |
int newhashes; |
63 |
- char global_manifest = 0; |
64 |
+ enum { |
65 |
+ GLOBAL_MANIFEST, /* Manifest.files.gz + Manifest */ |
66 |
+ SUBTREE_MANIFEST, /* Manifest.gz for recursive list of files */ |
67 |
+ EBUILD_MANIFEST, /* Manifest thick from thin */ |
68 |
+ CATEGORY_MANIFEST /* Manifest.gz with Manifest entries */ |
69 |
+ } type_manifest; |
70 |
struct stat s; |
71 |
struct timeval tv[2]; |
72 |
|
73 |
@@ -297,24 +330,48 @@ process_dir(const char *dir) |
74 |
tv[1].tv_usec = s.st_mtim.tv_nsec / 1000; |
75 |
} |
76 |
|
77 |
+ type_manifest = CATEGORY_MANIFEST; |
78 |
snprintf(path, sizeof(path), "%s/metadata/layout.conf", dir); |
79 |
if ((newhashes = parse_layout_conf(path)) != 0) { |
80 |
- global_manifest = 1; |
81 |
+ type_manifest = GLOBAL_MANIFEST; |
82 |
hashes = newhashes; |
83 |
+ } else { |
84 |
+ if ((p = strrchr(dir, '/')) != NULL) { |
85 |
+ p++; |
86 |
+ } else { |
87 |
+ p = dir; |
88 |
+ } |
89 |
+ |
90 |
+ if ( |
91 |
+ strcmp(p, "eclass") == 0 || |
92 |
+ strcmp(p, "licenses") == 0 || |
93 |
+ strcmp(p, "metadata") == 0 || |
94 |
+ strcmp(p, "profiles") == 0 || |
95 |
+ strcmp(p, "scripts") == 0 |
96 |
+ ) |
97 |
+ { |
98 |
+ type_manifest = SUBTREE_MANIFEST; |
99 |
+ } |
100 |
} |
101 |
|
102 |
+ /* If a Manifest file exists, this is an ebuild dir, unless we |
103 |
+ * already established this is the top level dir which also has a |
104 |
+ * Manifest file. */ |
105 |
snprintf(manifest, sizeof(manifest), "%s/%s", dir, str_manifest); |
106 |
- if (global_manifest || (f = fopen(manifest, "r")) == NULL) { |
107 |
+ if (type_manifest == GLOBAL_MANIFEST || |
108 |
+ (f = fopen(manifest, "r")) == NULL) |
109 |
+ { |
110 |
+ /* all of these types (GLOBAL, SUBTREE, CATEGORY) have a gzipped |
111 |
+ * Manifest */ |
112 |
gzFile mf; |
113 |
|
114 |
- /* recurse into subdirs */ |
115 |
if ((d = opendir(dir)) != NULL) { |
116 |
struct stat s; |
117 |
- char *my_manifest = |
118 |
- global_manifest ? str_manifest_files_gz : str_manifest_gz; |
119 |
+ char *my_manifest = str_manifest_gz; |
120 |
+ |
121 |
+ if (type_manifest == GLOBAL_MANIFEST) |
122 |
+ my_manifest = str_manifest_files_gz; |
123 |
|
124 |
- /* open up a gzipped Manifest to keep the hashes of the |
125 |
- * Manifests in the subdirs */ |
126 |
snprintf(manifest, sizeof(manifest), "%s/%s", dir, my_manifest); |
127 |
if ((mf = gzopen(manifest, "wb9")) == NULL) { |
128 |
fprintf(stderr, "failed to open file '%s' for writing: %s\n", |
129 |
@@ -323,22 +380,40 @@ process_dir(const char *dir) |
130 |
} |
131 |
|
132 |
while ((e = readdir(d)) != NULL) { |
133 |
+ /* ignore dotfiles (including . and ..) */ |
134 |
if (e->d_name[0] == '.') |
135 |
continue; |
136 |
+ /* ignore existing Manifests */ |
137 |
if (strcmp(e->d_name, my_manifest) == 0) |
138 |
continue; |
139 |
if (strcmp(e->d_name, str_manifest) == 0) |
140 |
continue; |
141 |
+ |
142 |
snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); |
143 |
if (!stat(path, &s)) { |
144 |
if (s.st_mode & S_IFDIR) { |
145 |
- char *mfest = process_dir(path); |
146 |
- if (mfest == NULL) { |
147 |
- gzclose(mf); |
148 |
- return NULL; |
149 |
+ if (type_manifest == SUBTREE_MANIFEST) { |
150 |
+ write_hashes_dir(dir, e->d_name, mf); |
151 |
+ if (strcmp(e->d_name, "metadata") == 0) { |
152 |
+ char buf[2048]; |
153 |
+ size_t len; |
154 |
+ len = snprintf(buf, sizeof(buf), |
155 |
+ "IGNORE timestamp\n" |
156 |
+ "IGNORE timestamp.chk\n" |
157 |
+ "IGNORE timestamp.commit\n" |
158 |
+ "IGNORE timestamp.x\n"); |
159 |
+ gzwrite(mf, buf, len); |
160 |
+ } |
161 |
+ } else { |
162 |
+ char *mfest = process_dir(path); |
163 |
+ if (mfest == NULL) { |
164 |
+ gzclose(mf); |
165 |
+ return NULL; |
166 |
+ } |
167 |
+ snprintf(path, sizeof(path), "%s/%s", |
168 |
+ e->d_name, mfest); |
169 |
+ write_hashes(dir, path, "MANIFEST", NULL, mf); |
170 |
} |
171 |
- snprintf(path, sizeof(path), "%s/%s", e->d_name, mfest); |
172 |
- write_hashes(dir, path, "MANIFEST", NULL, mf); |
173 |
} else if (s.st_mode & S_IFREG) { |
174 |
write_hashes(dir, e->d_name, "DATA", NULL, mf); |
175 |
} |
176 |
@@ -346,7 +421,7 @@ process_dir(const char *dir) |
177 |
} |
178 |
closedir(d); |
179 |
|
180 |
- if (global_manifest) { |
181 |
+ if (type_manifest == GLOBAL_MANIFEST) { |
182 |
char globmanifest[8192]; |
183 |
char buf[2048]; |
184 |
size_t len; |