From 61de8dc730e0c58b6b20470f068852b908e37416 Mon Sep 17 00:00:00 2001 From: cedric Date: Thu, 28 Apr 2011 13:25:14 +0000 Subject: [PATCH] ethumb: use xattr as cache when available. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ethumb@59004 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- configure.ac | 22 ++++++++++++++++++++++ src/lib/Ethumb.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ff6cfc5..c08646a 100644 --- a/configure.ac +++ b/configure.ac @@ -195,6 +195,27 @@ fi AM_CONDITIONAL(HAVE_LIBEXIF, test $HAVE_LIBEXIF = yes) AC_SUBST(HAVE_LIBEXIF) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include +#include + ]], + [[ +size_t tmp = listxattr("/", NULL, 0); +tmp = getxattr("/", "user.ethumb.md5", NULL, 0); +setxattr("/", "user.ethumb.md5", NULL, 0, 0); + ]])], + [ + AC_DEFINE(HAVE_XATTR, 1, [Define to 1 if you have 'listxattr', 'setxattr' and 'getxattr']) + have_xattr="yes" + ], + [have_xattr="no"]) + +AC_MSG_CHECKING([for Xattr]) +AC_MSG_RESULT([${have_xattr}]) + AC_SUBST(requirement_ethumb) AC_SUBST(requirement_ethumb_client) AC_SUBST(dbusservicedir) @@ -248,6 +269,7 @@ Summary: Configuration Options Summary: + * use xattr........: ${have_xattr} * maximum log level: ${with_max_log_level} * documentation....: ${build_doc} diff --git a/src/lib/Ethumb.c b/src/lib/Ethumb.c index 7035ea2..953215a 100644 --- a/src/lib/Ethumb.c +++ b/src/lib/Ethumb.c @@ -52,6 +52,10 @@ void *alloca (size_t); #include #include +#ifdef HAVE_XATTR +# include +#endif + #ifndef PATH_MAX # define PATH_MAX 4096 #endif @@ -824,6 +828,27 @@ _ethumb_generate_hash(const char *file) char *t; const unsigned char *c; +#ifdef HAVE_XATTR + ssize_t length; + + length = getxattr(file, "user.e.md5", NULL, 0); + + if (length > 0) + { + char *tmp; + + tmp = alloca(length); + length = getxattr(file, "user.e.md5", tmp, length); + + /* check if we have at least something that look like a md5 hash */ + if (length > 0 && (length == MD5_HASHBYTES * 2 + 1)) + { + tmp[length] = '\0'; + return eina_stringshare_add(tmp); + } + } +#endif + #define _check_uri_char(c) \ ((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08)) @@ -859,6 +884,10 @@ _ethumb_generate_hash(const char *file) } md5out[2 * n] = '\0'; +#ifdef HAVE_XATTR + setxattr(file, "user.e.md5", md5out, 2 * n + 1, 0); +#endif + DBG("md5=%s, file=%s", md5out, file); return eina_stringshare_add(md5out); } @@ -924,7 +953,6 @@ _ethumb_file_generate_path(Ethumb *e) const char *ext; int fdo_format; - fdo_format = _ethumb_file_check_fdo(e); if (e->thumb_dir) @@ -957,7 +985,6 @@ _ethumb_file_generate_path(Ethumb *e) else ext = "eet"; - fullname = ecore_file_realpath(e->src_path); hash = _ethumb_generate_hash(fullname); snprintf(buf, sizeof(buf), "%s/%s/%s.%s", thumb_dir, category, hash, ext); -- 2.7.4