subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Shahaf <...@daniel.shahaf.name>
Subject Re: svn commit: r1131383 - in /subversion/trunk/subversion: include/private/svn_magic.h libsvn_client/add.c libsvn_client/client.h libsvn_client/commit.c libsvn_subr/io.c libsvn_subr/magic.c
Date Sat, 04 Jun 2011 16:11:05 GMT
stsp@apache.org wrote on Sat, Jun 04, 2011 at 12:32:28 -0000:
> +/* Detect the mime-type of the file at LOCAL_ABSPATH using MAGIC_COOKIE.
> + * If the mime-type is binary return the result in *MIMETYPE.
> + * If the file is not a binary file or if its mime-type cannot be determined
> + * set *MIMETYPE to NULL. Allocate *MIMETYPE in RESULT_POOL.
> + * Use SCRATCH_POOL for temporary allocations. */
> +svn_error_t *
> +svn_magic__detect_binary_mimetype(const char **mimetype,
> +                                  const char *local_abspath,
> +                                  svn_magic__cookie_t *magic_cookie,
> +                                  apr_pool_t *result_pool,
> +                                  apr_pool_t *scratch_pool);
> +

As I said on IRC: I think this API is tailored for the caller and it
would seem more natural to me to move the "Ignore the result if it's
a binary type" to the caller.

> +svn_error_t *
> +svn_magic__detect_binary_mimetype(const char **mimetype,
> +                                  const char *local_abspath,
> +                                  svn_magic__cookie_t *magic_cookie,
> +                                  apr_pool_t *result_pool,
> +                                  apr_pool_t *scratch_pool)
> +{
> +  const char *magic_mimetype = NULL;
> +#ifdef HAVE_LIBMAGIC
> +  apr_finfo_t finfo;
> +
> +  /* Do not ask libmagic for the mime-types of empty files.
> +   * This prevents mime-types like "application/x-empty" from making
> +   * Subversion treat empty files as binary. */
> +  SVN_ERR(svn_io_stat(&finfo, local_abspath, APR_FINFO_SIZE, scratch_pool));
> +  if (finfo.size > 0)
> +    {

I've suggested to simply call libmagic and look for the
application/x-empty response, stsp claimed it wouldn't make
a noticeable difference in the current users (add and import),
I was convinced.

> +      magic_mimetype = magic_file(magic_cookie->magic, local_abspath);
> +      if (magic_mimetype)
> +        {
> +          /* Only return binary mime-types. */
> +          if (strncmp(magic_mimetype, "text/", 5) == 0)
> +            magic_mimetype = NULL;
> +          else
> +           {
> +             /* 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);
> +           }
> +        }
> +    }
> +#endif
> +
> +  *mimetype = magic_mimetype;
> +  return SVN_NO_ERROR;
> +}
> 
> 

Mime
View raw message