This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]Package extention recognition (revision 2)


----- Original Message -----
From: "Christopher Faylor" <cgf@redhat.com>
To: <cygwin-patches@cygwin.com>
Sent: Friday, January 25, 2002 09:24
Subject: Re: [PATCH]Package extention recognition (revision 2)


> On Fri, Jan 25, 2002 at 02:59:17AM -0800, Michael A Chase wrote:
> >And that test is still there, I moved it into the if () so something like
> >".tar.bz2" wouldn't trigger the return .... : 0;  If all the ifs fail,
> >return 0; still occurs.
>
> Hmm.  Seems like someone has "improved" this code from when I wrote it.

Is the "improved" version my change or the way I found it?

> My version checked for a trailing component.  If it existed, it returned
> the index into the string.
>
> This version sort of does the same thing but if there is a .tar.bz2
> anywhere in the string prior to trailing component, it will fail
> regardless of whether the filename ends with .tar .tar.gz or .tar.bz2.
>
> Perhaps that is an acceptable risk but it puzzles me why anyone would
> move from an algorithm that was foolproof to one that wasn't.

I can go either way.  It is hard for me to imagine foo-0.0.tar.bz2.tar.gz
being valid, but my patched version would accept it while the original
version would reject it.  Neither version is fool proof for some values of
fool; both would pass foo-0.0.tar.gz.tar.bz2.  If you like I can move the
'(end - ext) == x' test back to the 'return' statement.

The trailing ';' on the 'if' statements still have to go or the ".tar" check
will never be executed.

I hope I'm more articulate after taking my nap.

--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

--- filemanip.cc-0 Thu Jan 24 16:43:57 2002
+++ filemanip.cc Fri Jan 25 02:26:39 2002
@@ -66,13 +66,14 @@ find_tar_ext (const char *path)
 {
   char *end = strchr (path, '\0');
   /* check in longest first order */
-  char *ext = strstr (path, ".tar.bz2");
-  if (ext)
-    return (end - ext) == 8 ? ext - path : 0;
-  if ((ext = strstr (path, ".tar.gz")));
-  return (end - ext) == 7 ? ext - path : 0;
-  if ((ext = strstr (path, ".tar")));
-  return (end - ext) == 4 ? ext - path : 0;
+  char *ext;
+  if ((ext = strstr (path, ".tar.bz2")) && (end - ext) == 8)
+    return ext - path;
+  if ((ext = strstr (path, ".tar.gz")) && (end - ext) == 7)
+    return ext - path;
+  if ((ext = strstr (path, ".tar")) && (end - ext) == 4)
+    return ext - path;
+  return 0;
 }

 /* Parse a filename into package, version, and extension components. */




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]