[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [rfc] leverage -x/-X tar call to pass more tar options



On Sun, Jul 04, 2010 at 01:34:25AM +0200, Pierre Habouzit wrote:
> On Sat, Jul 03, 2010 at 06:30:58PM -0500, Jonathan Nieder wrote:
> > Hi,
> > 
> > Pierre Habouzit wrote:
> > 
> > > The point is that doing chained pipes is pretty annoying from C
> > > (especially if you want to use parallelism in the process), plus it kind
> > > of make sense for many kind of operations where you don't need
> > > --fsys-tarfile anymore: e.g. extracting a single file can be done with:
> > > 
> > >     dpkg-deb -x file.deb some-dir ./path/to/file/to/extract
> > 
> > I have wished for something like this before.
> > 
> > > +++ b/dpkg-deb/extract.c
> > > @@ -325,7 +329,17 @@ void extracthalf(const char *debar, const char *directory,
> > >  
> > >        unsetenv("TAR_OPTIONS");
> > >  
> > > -      execlp(TAR, "tar", buffer, "-", NULL);
> > > +      for (i = 0; taropts && taropts[i]; i++);
> > 
> > Produces a warning from gcc.
> > 
> > > +      arg = targv = m_malloc((5 + i + 1) * sizeof(targv[0]));
> > 
> > Why not (4 + i) * sizeof(targv[0])?

actually I missed that question, it's because in a previous iteration of
the patch, there was another argument needed, which it doesn't anymore.

> > > +      *arg++ = "tar";
> > > +      *arg++ = buffer;
> > > +      *arg++ = "-";
> > > +      if (i) {
> > 
> > Needed for the !taropts case.  Good.

actually this isn't really needed anymore either (before when !taropts,
I had kept the old code, and I didn't used the malloced argv).
memcpy(dst, src, 0) will do what it should, even when src is NULL.

But it's only cosmetics of course.

> > > +        mempcpy(arg, taropts, i * sizeof(taropts[0]));
> > > +        arg += i;
> > > +      }
> > > +      *arg++ = NULL;
> > > +      execvp(TAR, (char *const *)targv);
> > >        ohshite(_("failed to exec tar"));
> > >      }
> > >      close(p2[0]);
> > 
> > I couldn’t find any other uses of mempcpy in dpkg, so it might be better
> > to use memcpy() or use a wrapper like git does.
>   err that was a typo actually sorry, the previous version was arg =
> mempcpy(...), I fixed it to avoid the mempcpy and forgot to remove the
> 'p'.
> 
> I agree with the rest of your mail of course.
> -- 
> ·O·  Pierre Habouzit
> ··O                                                madcoder@debian.org
> OOO                                                http://www.madism.org

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org


Reply to: