116
120
pi->maxpartlen == refi->maxpartlen);
119
void do_auto(const char *const *argv) {
124
do_auto(const char *const *argv)
120
126
const char *partfile;
121
struct partinfo *pi, *refi, *npi, **partlist, *otherthispart;
127
struct partinfo *refi, **partlist, *otherthispart;
122
128
struct partqueue *pq;
130
133
if (!opt_outputfile)
131
134
badusage(_("--auto requires the use of the --output option"));
156
160
/* If we already have a copy of this version we ignore it and prefer the
157
161
* new one, but we still want to delete the one in the depot, so we
158
* save its partinfo (with the filename) for later. This also prevents
159
* us from accidentally deleting the source file.
162
* save its partinfo (with the filename) for later. This also prevents
163
* us from accidentally deleting the source file. */
161
164
otherthispart= partlist[refi->thispartn-1];
162
165
partlist[refi->thispartn-1]= refi;
163
166
for (j=refi->maxpartn-1; j>=0 && partlist[j]; j--);
167
part= fopen(partfile,"r");
168
if (!part) ohshite(_("unable to reopen part file `%.250s'"),partfile);
169
buffer= nfmalloc(refi->filesize);
170
nr= fread(buffer,1,refi->filesize,part);
171
if (nr != refi->filesize) rerreof(part,partfile);
172
if (getc(part) != EOF) ohshit(_("part file `%.250s' has trailing garbage"),partfile);
173
if (ferror(part)) rerr(partfile);
175
p = nfmalloc(strlen(opt_depotdir) + 50);
176
q = nfmalloc(strlen(opt_depotdir) + 200);
177
sprintf(p, "%st.%lx", opt_depotdir, (long)getpid());
178
sprintf(q, "%s%s.%lx.%x.%x", opt_depotdir, refi->md5sum,
179
refi->maxpartlen,refi->thispartn,refi->maxpartn);
181
if (!part) ohshite(_("unable to open new depot file `%.250s'"),p);
182
nr= fwrite(buffer,1,refi->filesize,part);
183
if (nr != refi->filesize) werr(p);
185
ohshite(_("unable to flush file '%s'"), p);
186
if (fsync(fileno(part)))
173
m_asprintf(&p, "%st.%lx", opt_depotdir, (long)getpid());
174
m_asprintf(&q, "%s%s.%jx.%x.%x", opt_depotdir, refi->md5sum,
175
(intmax_t)refi->maxpartlen, refi->thispartn, refi->maxpartn);
177
fd_src = open(partfile, O_RDONLY);
179
ohshite(_("unable to reopen part file `%.250s'"), partfile);
180
fd_dst = creat(p, 0644);
182
ohshite(_("unable to open new depot file `%.250s'"), p);
184
fd_fd_copy(fd_src, fd_dst, refi->filesize, _("extracting split part"));
187
187
ohshite(_("unable to sync file '%s'"), p);
188
if (fclose(part)) werr(p);
189
ohshite(_("unable to close file '%s'"), p);
189
192
if (rename(p,q)) ohshite(_("unable to rename new depot file `%.250s' to `%.250s'"),p,q);
191
196
printf(_("Part %d of package %s filed (still want "),refi->thispartn,refi->package);
192
197
/* There are still some parts missing. */
233
240
ohshit(_("unable to stat `%.250s'"),pq->info.filename);
234
241
if (S_ISREG(stab.st_mode)) {
235
242
bytes= stab.st_size;
236
printf(_(" %s (%lu bytes)\n"),pq->info.filename,bytes);
243
printf(_(" %s (%jd bytes)\n"), pq->info.filename, (intmax_t)bytes);
238
245
printf(_(" %s (not a plain file)\n"),pq->info.filename);
241
248
if (!*head) putchar('\n');
243
250
head= N_("Packages not yet reassembled:\n");
244
251
for (pq= queue; pq; pq= pq->nextinqueue) {
245
255
if (!pq->info.md5sum) continue;
246
256
mustgetpartinfo(pq->info.filename,&ti);
247
257
fputs(gettext(head),stdout); head= "";
248
258
printf(_(" Package %s: part(s) "), ti.package);
250
260
for (i=0; i<ti.maxpartn; i++) {
261
struct partqueue *qq;
252
264
qq && !(partmatches(&qq->info,&ti) && qq->info.thispartn == i+1);
253
265
qq= qq->nextinqueue);
258
270
if (!S_ISREG(stab.st_mode))
259
271
ohshit(_("part file `%.250s' is not a plain file"),qq->info.filename);
260
272
bytes+= stab.st_size;
261
qq->info.md5sum= NULL; /* don't find this package again */
274
/* Don't find this package again. */
275
qq->info.md5sum = NULL;
264
printf(_("(total %lu bytes)\n"),bytes);
278
printf(_("(total %jd bytes)\n"), (intmax_t)bytes);
266
280
m_output(stdout, _("<standard output>"));
269
285
enum discardwhich { ds_junk, ds_package, ds_all };