From: Tollef Fog Heen Date: Sun, 20 Jan 2008 22:36:09 +0000 (+0100) Subject: Factor skipping files into its own function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2654bfcfb989886e44fc980e277e703a0e6ac045;p=dpkg Factor skipping files into its own function Move the common bits of tarfile where it skips input files into tarfile_skip_one_forward. --- diff --git a/src/archives.c b/src/archives.c index f81ccbd2..9ab31588 100644 --- a/src/archives.c +++ b/src/archives.c @@ -232,6 +232,28 @@ int tarfileread(void *ud, char *buf, int len) { return r; } +void tarfile_skip_one_forward(struct TarInfo *ti, + struct fileinlist **oldnifd, + struct fileinlist *nifd) { + struct tarcontext *tc= (struct tarcontext*)ti->UserData; + size_t r; + char databuf[TARBLKSZ]; + + obstack_free(&tar_obs, nifd); + tc->newfilesp= oldnifd; + *oldnifd = 0; + + /* We need to advance the tar file to the next object, so read the + * file data and set it to oblivion. + */ + if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) { + char fnamebuf[256]; + fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name)); + r= ti->Size % TARBLKSZ; + if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r); + } +} + int fnameidlu; struct varbuf fnamevb; struct varbuf fnametmpvb; @@ -408,22 +430,10 @@ int tarobject(struct TarInfo *ti) { ? nifd->namenode->divert->useinstead->name : ""); if (filter_should_skip(ti) == 1) { - struct filenamenode *fnn = findnamenode(ti->Name, 0); - fnn->flags &= ~fnnf_new_inarchive; - obstack_free(&tar_obs, nifd); - tc->newfilesp= oldnifd; - *oldnifd = 0; - - /* We need to advance the tar file to the next object, so read the - * file data and set it to oblivion. - */ - if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) { - char fnamebuf[256]; - fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name)); - r= ti->Size % TARBLKSZ; - if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r); - } - return 0; + struct filenamenode *fnn = findnamenode(ti->Name, 0); + fnn->flags &= ~fnnf_new_inarchive; + tarfile_skip_one_forward(ti, oldnifd, nifd); + return 0; } if (nifd->namenode->divert && nifd->namenode->divert->camefrom) { @@ -604,20 +614,7 @@ int tarobject(struct TarInfo *ti) { if (existingdirectory) return 0; if (keepexisting) { - obstack_free(&tar_obs, nifd); - tc->newfilesp= oldnifd; - *oldnifd = 0; - - /* We need to advance the tar file to the next object, so read the - * file data and set it to oblivion. - */ - if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) { - char fnamebuf[256]; - fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name)); - r= ti->Size % TARBLKSZ; - if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r); - } - + tarfile_skip_one_forward(ti, oldnifd, nifd); return 0; }