You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2011/06/04 15:04:51 UTC

svn commit: r1131389 - /subversion/trunk/subversion/libsvn_subr/magic.c

Author: stsp
Date: Sat Jun  4 13:04:51 2011
New Revision: 1131389

URL: http://svn.apache.org/viewvc?rev=1131389&view=rev
Log:
Work around older libmagic versions that don't define MAGIC_MIME_TYPE.

This should fix the centos buildbot.

* subversion/libsvn_subr/magic.c: 
  (svn_magic__init): If MAGIC_MIME_TYPE isn't supported use MAGIC_MIME instead.
  (svn_magic__detect_binary_mimetype): Strip charset information from the
   string returned by libmagic if MAGIC_MIME was used.

Modified:
    subversion/trunk/subversion/libsvn_subr/magic.c

Modified: subversion/trunk/subversion/libsvn_subr/magic.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/magic.c?rev=1131389&r1=1131388&r2=1131389&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/magic.c (original)
+++ subversion/trunk/subversion/libsvn_subr/magic.c Sat Jun  4 13:04:51 2011
@@ -70,7 +70,14 @@ svn_magic__init(svn_magic__cookie_t **ma
   mc = apr_palloc(result_pool, sizeof(*mc));
 
   /* Initialise libmagic. */
+#ifndef MAGIC_MIME_TYPE
+  /* Some old versions of libmagic don't support MAGIC_MIME_TYPE.
+   * We can use MAGIC_MIME instead. It returns more than we need
+   * but we can work around that (see below). */
+  mc->magic = magic_open(MAGIC_MIME | MAGIC_ERROR);
+#else
   mc->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR);
+#endif
   if (mc->magic)
     {
       /* This loads the default magic database.
@@ -115,6 +122,14 @@ svn_magic__detect_binary_mimetype(const 
             magic_mimetype = NULL;
           else
            {
+#ifndef MAGIC_MIME_TYPE
+             char *p;
+
+             /* Strip off trailing stuff like " charset=ascii". */
+             p = strchr(magic_mimetype, ' ');
+             if (p)
+              *p = '\0';
+#endif
              /* The string is allocated from memory managed by libmagic so
               * we must copy it to the result pool. */
              magic_mimetype = apr_pstrdup(result_pool, magic_mimetype);



Re: svn commit: r1131389 - /subversion/trunk/subversion/libsvn_subr/magic.c

Posted by Stefan Sperling <st...@elego.de>.
On Fri, Jun 24, 2011 at 09:49:31PM +0300, Daniel Shahaf wrote:
> > +#ifndef MAGIC_MIME_TYPE
> > +             char *p;
> > +
> > +             /* Strip off trailing stuff like " charset=ascii". */
> > +             p = strchr(magic_mimetype, ' ');
> > +             if (p)
> > +              *p = '\0';
> 
> What is 'magic_mimetype' here?  Is it guaranteed to contain a space, or
> can it be 'text/plain;charset=ascii' ?

In all examples I've seen it was a space.
I suppose the only canonical reference on this is the libmagic
source code, since this is not standardized in any way.

> i.e., should the strchr look for a semicolon?

I would only add that if we get someone reporting a bug about it.

You see, if this value is bogus in some way, it will not pass the
subsequent mime-type syntax validation step. So we will never use it
and just fall back to what we did without libmagic.
So this is not a big issue. It's cosmetic.

Re: svn commit: r1131389 - /subversion/trunk/subversion/libsvn_subr/magic.c

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
stsp@apache.org wrote on Sat, Jun 04, 2011 at 13:04:51 -0000:
> Author: stsp
> Date: Sat Jun  4 13:04:51 2011
> New Revision: 1131389
> 
> URL: http://svn.apache.org/viewvc?rev=1131389&view=rev
> Log:
> Work around older libmagic versions that don't define MAGIC_MIME_TYPE.
> 
> This should fix the centos buildbot.
> 
> * subversion/libsvn_subr/magic.c: 
>   (svn_magic__init): If MAGIC_MIME_TYPE isn't supported use MAGIC_MIME instead.
>   (svn_magic__detect_binary_mimetype): Strip charset information from the
>    string returned by libmagic if MAGIC_MIME was used.
> 
> Modified:
>     subversion/trunk/subversion/libsvn_subr/magic.c
> 
> Modified: subversion/trunk/subversion/libsvn_subr/magic.c
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/magic.c?rev=1131389&r1=1131388&r2=1131389&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/libsvn_subr/magic.c (original)
> +++ subversion/trunk/subversion/libsvn_subr/magic.c Sat Jun  4 13:04:51 2011
> @@ -70,7 +70,14 @@ svn_magic__init(svn_magic__cookie_t **ma
>    mc = apr_palloc(result_pool, sizeof(*mc));
>  
>    /* Initialise libmagic. */
> +#ifndef MAGIC_MIME_TYPE
> +  /* Some old versions of libmagic don't support MAGIC_MIME_TYPE.
> +   * We can use MAGIC_MIME instead. It returns more than we need
> +   * but we can work around that (see below). */
> +  mc->magic = magic_open(MAGIC_MIME | MAGIC_ERROR);
> +#else
>    mc->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR);
> +#endif
>    if (mc->magic)
>      {
>        /* This loads the default magic database.
> @@ -115,6 +122,14 @@ svn_magic__detect_binary_mimetype(const 
>              magic_mimetype = NULL;
>            else
>             {
> +#ifndef MAGIC_MIME_TYPE
> +             char *p;
> +
> +             /* Strip off trailing stuff like " charset=ascii". */
> +             p = strchr(magic_mimetype, ' ');
> +             if (p)
> +              *p = '\0';

What is 'magic_mimetype' here?  Is it guaranteed to contain a space, or
can it be 'text/plain;charset=ascii' ?

i.e., should the strchr look for a semicolon?

(The libmagic ftp mirror is down, and my man page doesn't mention
MAGIC_MIME, so I'm not easily able to check the docs of some old
libmagic version.)


> +#endif
>               /* The string is allocated from memory managed by libmagic so
>                * we must copy it to the result pool. */
>               magic_mimetype = apr_pstrdup(result_pool, magic_mimetype);
> 
> 

Re: svn commit: r1131389 - /subversion/trunk/subversion/libsvn_subr/magic.c

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
stsp@apache.org wrote on Sat, Jun 04, 2011 at 13:04:51 -0000:
> Author: stsp
> Date: Sat Jun  4 13:04:51 2011
> New Revision: 1131389
> 
> URL: http://svn.apache.org/viewvc?rev=1131389&view=rev
> Log:
> Work around older libmagic versions that don't define MAGIC_MIME_TYPE.
> 
> This should fix the centos buildbot.
> 
> * subversion/libsvn_subr/magic.c: 
>   (svn_magic__init): If MAGIC_MIME_TYPE isn't supported use MAGIC_MIME instead.
>   (svn_magic__detect_binary_mimetype): Strip charset information from the
>    string returned by libmagic if MAGIC_MIME was used.
> 
> Modified:
>     subversion/trunk/subversion/libsvn_subr/magic.c
> 
> Modified: subversion/trunk/subversion/libsvn_subr/magic.c
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/magic.c?rev=1131389&r1=1131388&r2=1131389&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/libsvn_subr/magic.c (original)
> +++ subversion/trunk/subversion/libsvn_subr/magic.c Sat Jun  4 13:04:51 2011
> @@ -70,7 +70,14 @@ svn_magic__init(svn_magic__cookie_t **ma
>    mc = apr_palloc(result_pool, sizeof(*mc));
>  
>    /* Initialise libmagic. */
> +#ifndef MAGIC_MIME_TYPE
> +  /* Some old versions of libmagic don't support MAGIC_MIME_TYPE.
> +   * We can use MAGIC_MIME instead. It returns more than we need
> +   * but we can work around that (see below). */
> +  mc->magic = magic_open(MAGIC_MIME | MAGIC_ERROR);
> +#else
>    mc->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR);
> +#endif
>    if (mc->magic)
>      {
>        /* This loads the default magic database.
> @@ -115,6 +122,14 @@ svn_magic__detect_binary_mimetype(const 
>              magic_mimetype = NULL;
>            else
>             {
> +#ifndef MAGIC_MIME_TYPE
> +             char *p;
> +
> +             /* Strip off trailing stuff like " charset=ascii". */
> +             p = strchr(magic_mimetype, ' ');
> +             if (p)
> +              *p = '\0';

What is 'magic_mimetype' here?  Is it guaranteed to contain a space, or
can it be 'text/plain;charset=ascii' ?

i.e., should the strchr look for a semicolon?

(The libmagic ftp mirror is down, and my man page doesn't mention
MAGIC_MIME, so I'm not easily able to check the docs of some old
libmagic version.)


> +#endif
>               /* The string is allocated from memory managed by libmagic so
>                * we must copy it to the result pool. */
>               magic_mimetype = apr_pstrdup(result_pool, magic_mimetype);
> 
>