48
48
char *controlchunk;
57
57
fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e));
58
58
return RET_ERRNO(e);
64
close(pipe1[0]);close(pipe1[1]);
64
close(pipe1[0]); close(pipe1[1]);
65
65
fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e));
66
66
return RET_ERRNO(e);
72
72
fprintf(stderr, "Error %d forking: %s\n", e, strerror(e));
73
73
result = RET_ERRNO(e);
74
close(pipe1[0]);close(pipe1[1]);
75
close(pipe2[0]);close(pipe2[1]);
74
close(pipe1[0]); close(pipe1[1]);
75
close(pipe2[0]); close(pipe2[1]);
82
if( dup2(pipe1[1],1) < 0 )
82
if (dup2(pipe1[1], 1) < 0)
84
close(pipe1[0]);close(pipe1[1]);
85
close(pipe2[0]);close(pipe2[1]);
84
close(pipe1[0]); close(pipe1[1]);
85
close(pipe2[0]); close(pipe2[1]);
86
86
//TODO without explicit path
87
87
ret = execl("/usr/bin/ar",
88
88
"ar", "p", debfile, "control.tar.gz",
99
99
result = RET_ERRNO(e);
100
100
fprintf(stderr, "Error %d forking: %s\n", e, strerror(e));
101
close(pipe1[0]);close(pipe1[1]);
102
close(pipe2[0]);close(pipe2[1]);
101
close(pipe1[0]); close(pipe1[1]);
102
close(pipe2[0]); close(pipe2[1]);
104
} else if( tar == 0 ) {
104
} else if (tar == 0) {
106
106
/* calling tar */
107
if( dup2(pipe1[0],0) < 0 )
109
if( dup2(pipe2[1],1) < 0 )
111
close(pipe1[0]);close(pipe1[1]);
112
close(pipe2[0]);close(pipe2[1]);
107
if (dup2(pipe1[0], 0) < 0)
109
if (dup2(pipe2[1], 1) < 0)
111
close(pipe1[0]); close(pipe1[1]);
112
close(pipe2[0]); close(pipe2[1]);
113
113
//TODO without explicit path
114
114
execl("/bin/tar", "tar", "-xOzf", "-",
115
115
brokentar?"control":"./control",
127
127
controlchunk = NULL;
130
if( RET_IS_OK(result) ) {
130
if (RET_IS_OK(result)) {
131
131
size_t len; char *afterchanges;
133
133
r = readtextfilefd(pipe2[0],
135
"output from ar p <debfile> control.tar.gz | tar -XOzf - control":
136
"output from ar p <debfile> control.tar.gz | tar -XOzf - ./control",
135
"output from ar p <debfile> control.tar.gz | tar -XOzf - control":
136
"output from ar p <debfile> control.tar.gz | tar -XOzf - ./control",
137
137
&controlchunk, NULL);
139
len = chunk_extract(controlchunk, controlchunk, &afterchanges);
139
len = chunk_extract(controlchunk, controlchunk,
142
if( *afterchanges != '\0' ) {
143
if (*afterchanges != '\0') {
144
145
"Unexpected emtpy line in control information within '%s'\n"
145
146
"(obtained via 'ar p %s control.tar.gz | tar -XOzf - %scontrol')\n",
153
if( r == RET_NOTHING ) {
154
if (r == RET_NOTHING) {
154
155
free(controlchunk);
155
156
controlchunk = NULL;
156
fprintf(stderr, "No control information found in .deb!\n");
157
/* only report error now if we haven't try everything yet */
158
"No control information found in .deb!\n");
159
/* only report error now,
160
* if we haven't try everything yet */
159
162
r = RET_ERROR_MISSING;
161
RET_UPDATE(result,r);
164
RET_UPDATE(result, r);
165
while( ar != -1 || tar != -1 ) {
168
while (ar != -1 || tar != -1) {
166
169
pid=wait(&status);
169
RET_UPDATE(result,RET_ERRNO(errno));
172
RET_UPDATE(result, RET_ERRNO(errno));
173
if( !WIFEXITED(status) ) {
174
fprintf(stderr,"Ar exited unnaturally!\n");
176
if (!WIFEXITED(status)) {
178
"Ar exited unnaturally!\n");
175
179
result = RET_ERROR;
176
} else if( WEXITSTATUS(status) != 0) {
177
fprintf(stderr,"Error from ar for '%s': %d\n",
178
debfile, WEXITSTATUS(status));
180
} else if (WEXITSTATUS(status) != 0) {
182
"Error from ar for '%s': %d\n", debfile, WEXITSTATUS(status));
179
183
result = RET_ERROR;
181
} else if( pid == tar ) {
185
} else if (pid == tar) {
183
if( !WIFEXITED(status) ) {
184
fprintf(stderr,"Tar exited unnaturally!\n");
187
if (!WIFEXITED(status)) {
189
"Tar exited unnaturally!\n");
185
190
result = RET_ERROR;
186
} else if( !brokentar && WEXITSTATUS(status) == 2 ) {
187
if( RET_IS_OK(result) )
191
} else if (!brokentar && WEXITSTATUS(status) == 2) {
192
if (RET_IS_OK(result))
188
193
result = RET_NOTHING;
189
} else if( WEXITSTATUS(status) != 0 ) {
190
fprintf(stderr,"Error from tar for control.tar.gz within '%s': %d\n",
194
} else if (WEXITSTATUS(status) != 0) {
196
"Error from tar for control.tar.gz within '%s': %d\n",
192
198
WEXITSTATUS(status));
193
199
result = RET_ERROR;
197
fprintf(stderr,"Who is %d, and why does this bother me?\n",(int)pid);
204
"Who is %d, and why does this bother me?\n", (int)pid);
202
if( RET_IS_OK(result) ) {
203
if( controlchunk == NULL )
209
if (RET_IS_OK(result)) {
210
if (controlchunk == NULL)
204
211
/* we got not data but tar gave not error.. */
205
212
return RET_ERROR_MISSING;
213
retvalue extractcontrol(char **control,const char *debfile) {
220
retvalue extractcontrol(char **control, const char *debfile) {
216
223
r = try_extractcontrol(control, debfile, false);
217
if( r != RET_NOTHING )
224
if (r != RET_NOTHING)
219
226
/* perhaps the control.tar.gz is packaged by hand wrongly,
221
228
r = try_extractcontrol(control, debfile, true);
223
fprintf(stderr, "WARNING: '%s' contains a broken/unusual control.tar.gz.\n"
224
"reprepro was able to work around this but other tools or versions might not.\n", debfile);
231
"WARNING: '%s' contains a broken/unusual control.tar.gz.\n"
232
"reprepro was able to work around this but other tools or versions might not.\n",
226
assert( r != RET_NOTHING );
235
assert (r != RET_NOTHING);
230
239
retvalue getfilelist(/*@out@*/char **filelist, /*@out@*/size_t *size, const char *debfile) {
231
fprintf(stderr, "Extraction of file list without libarchive currently not implemented.\n");
241
"Extraction of file list without libarchive currently not implemented.\n");
232
242
return RET_ERROR;
239
249
struct filelistcompressor c;
243
253
#error this still needs to be reimplemented...
244
254
result = filelistcompressor_setup(&c);
245
if( RET_WAS_ERROR(result) )
255
if (RET_WAS_ERROR(result))
250
260
ret = pipe(pipe1);
253
263
fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e));
254
264
filelistcompressor_cancel(&c);
258
268
ret = pipe(pipe2);
261
271
fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e));
262
close(pipe1[0]);close(pipe1[1]);
272
close(pipe1[0]); close(pipe1[1]);
263
273
filelistcompressor_cancel(&c);
264
274
return RET_ERRNO(e);
270
280
fprintf(stderr, "Error %d forking: %s\n", e, strerror(e));
271
281
result = RET_ERRNO(e);
272
close(pipe1[0]);close(pipe1[1]);
273
close(pipe2[0]);close(pipe2[1]);
282
close(pipe1[0]); close(pipe1[1]);
283
close(pipe2[0]); close(pipe2[1]);
274
284
filelistcompressor_cancel(&c);
281
if( dup2(pipe1[1],1) < 0 )
291
if (dup2(pipe1[1], 1) < 0)
283
close(pipe1[0]);close(pipe1[1]);
284
close(pipe2[0]);close(pipe2[1]);
293
close(pipe1[0]); close(pipe1[1]);
294
close(pipe2[0]); close(pipe2[1]);
285
295
//TODO without explicit path
286
296
ret = execl("/usr/bin/ar",
287
297
"ar", "p", debfile, "data.tar.gz",
298
308
result = RET_ERRNO(e);
299
309
fprintf(stderr, "Error %d forking: %s\n", e, strerror(e));
300
close(pipe1[0]);close(pipe1[1]);
301
close(pipe2[0]);close(pipe2[1]);
310
close(pipe1[0]); close(pipe1[1]);
311
close(pipe2[0]); close(pipe2[1]);
303
} else if( tar == 0 ) {
313
} else if (tar == 0) {
305
315
/* calling tar */
306
if( dup2(pipe1[0],0) < 0 )
308
if( dup2(pipe2[1],1) < 0 )
310
close(pipe1[0]);close(pipe1[1]);
311
close(pipe2[0]);close(pipe2[1]);
316
if (dup2(pipe1[0], 0) < 0)
318
if (dup2(pipe2[1], 1) < 0)
320
close(pipe1[0]); close(pipe1[1]);
321
close(pipe2[0]); close(pipe2[1]);
312
322
//TODO without explicit path
313
323
execl("/bin/tar", "tar", "-tzf", "-", ENDOFARGUMENTS);
321
close(pipe1[0]);close(pipe1[1]);
331
close(pipe1[0]); close(pipe1[1]);
325
if( RET_IS_OK(result) ) do {
335
if (RET_IS_OK(result)) do {
326
336
ssize_t bytes_read;
329
if( listsize <= len + 512 ) {
339
if (listsize <= len + 512) {
332
342
listsize = len + 1024;
333
343
n = realloc(list, listsize);
344
if (FAILEDTOALLOC(n)) {
335
345
result = RET_ERROR_OOM;
342
352
bytes_read = read(pipe2[0], list+len, listsize-len-1);
343
if( bytes_read < 0 ) {
353
if (bytes_read < 0) {
345
355
fprintf(stderr, "Error %d reading from pipe: %s\n",
347
357
result = RET_ERRNO(e);
349
} else if( bytes_read == 0 )
359
} else if (bytes_read == 0)
351
else while( bytes_read > 0 ) {
352
if( list[len] == '\0' ) {
361
else while (bytes_read > 0) {
362
if (list[len] == '\0') {
354
364
"Unexpected NUL character from tar while getting file list from %s!\n", debfile);
355
365
result = RET_ERROR;
357
} else if( list[len] == '\n' ) {
358
if( len > last+ignore && list[len-1] != '/' ) {
367
} else if (list[len] == '\n') {
368
if (len > last+ignore && list[len-1] != '/') {
359
369
list[len] = '\0';
409
while( ar != -1 || tar != -1 ) {
419
while (ar != -1 || tar != -1) {
410
420
pid=wait(&status);
413
RET_UPDATE(result,RET_ERRNO(errno));
423
RET_UPDATE(result, RET_ERRNO(errno));
417
if( !WIFEXITED(status) ||
427
if (!WIFEXITED(status) ||
418
428
WEXITSTATUS(status) != 0) {
419
fprintf(stderr,"Error from ar for '%s': %d\n",
421
WEXITSTATUS(status));
430
"Error from ar for '%s': %d\n", debfile, WEXITSTATUS(status));
422
431
result = RET_ERROR;
424
} else if( pid == tar ) {
433
} else if (pid == tar) {
426
if( !WIFEXITED(status) ||
427
WEXITSTATUS(status) != 0 ) {
428
fprintf(stderr,"Error from tar for data.tar.gz within '%s': %d\n",
435
if (!WIFEXITED(status) ||
436
WEXITSTATUS(status) != 0) {
438
"Error from tar for data.tar.gz within '%s': %d\n",
430
440
WEXITSTATUS(status));
431
441
result = RET_ERROR;
435
fprintf(stderr,"Who is %d, and why does this bother me?\n",pid);
446
"Who is %d, and why does this bother me?\n", pid);
439
if( RET_IS_OK(result) )
450
if (RET_IS_OK(result))
440
451
return filelistcompressor_finish(&c, filelist);
442
453
filelistcompressor_cancel(&c);