Date: Mon, 12 Apr 2010 22:49:52 -0700 From: Garrett Cooper <gcooper@FreeBSD.org> To: Tim Kientzle <kientzle@freebsd.org> Cc: Perforce Change Reviews <perforce@freebsd.org> Subject: Re: PERFORCE change 176831 for review Message-ID: <l2y364299f41004122249q2f5734a7j89be807581e42dac@mail.gmail.com> In-Reply-To: <4BC3EB5B.5070801@freebsd.org> References: <201004121230.o3CCUsIX029146@repoman.freebsd.org> <4BC3EB5B.5070801@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Apr 12, 2010 at 8:56 PM, Tim Kientzle <kientzle@freebsd.org> wrote: > Garrett Cooper wrote: >> >> +FILE* >> +unpack_file_to_fd(const char *pkg, const char *file) >> +{ > > .... >> >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 r =3D arch= ive_read_extract(archive, >> archive_entry, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 EX= TRACT_ARCHIVE_FLAGS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (r =3D= =3D ARCHIVE_OK) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 if (Verbose) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 printf("X - %s\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry_pathname); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 fd =3D fopen(entry_pathname, "r"); > > This is potentially race-prone. =A0I would suggest instead that > you: > > =A0 int fd =3D open(entry_pathname, O_RDWR | O_CREAT, ...) > =A0 archive_read_data_into_fd(a, fd); > > Then rewind the fd and return it. =A0archive_read_extract() > is handy but it's way overkill for this kind of simple > operation. =A0I would also put in a simple verification > that the entry you found is a regular entry: > =A0 archive_entry_filetype(entry) =3D=3D AE_IFREG Ok. What does a regular entry correspond to (I assume not a regular file)? >> + * NOTE: the exit code is 0 / 1 so that this can be fed directly into >> exit >> + * when doing piped tar commands for copying hierarchies *hint*, *hint*=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?l2y364299f41004122249q2f5734a7j89be807581e42dac>