Re: [rfc] leverage -x/-X tar call to pass more tar options
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])?
>
> > + *arg++ = "tar";
> > + *arg++ = buffer;
> > + *arg++ = "-";
> > + if (i) {
>
> Needed for the !taropts case. Good.
>
> > + 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
Reply to: