[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

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

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Sat, 4 Jun 2011 19:11:05 +0300

stsp_at_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;
> +}
>
>
Received on 2011-06-04 18:11:50 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.