ethumb - fix clients going right to disk and getting half written thumbs
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Wed, 19 Feb 2014 07:04:52 +0000 (16:04 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Wed, 19 Feb 2014 13:13:09 +0000 (22:13 +0900)
client still do stats (not async) but at least they dont get
half-baked thumbs now

src/lib/ethumb/ethumb.c

index 35163c1..761d56d 100644 (file)
@@ -1363,8 +1363,8 @@ EAPI Eina_Bool
 ethumb_image_save(Ethumb *e)
 {
    Eina_Bool r;
-   char *dname;
-   char flags[256];
+   char *dname, *buf, flags[256];
+   int len;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
 
@@ -1388,18 +1388,28 @@ ethumb_image_save(Ethumb *e)
         free(dname);
         return EINA_FALSE;
      }
+   buf = alloca(strlen(e->thumb_path) + 1 + 5);
+   strcpy(buf, dname);
+   len = strlen(dname);
+   strcpy(&(buf[len]), "/.tmp.");
+   strcpy(&(buf[len + 6]), e->thumb_path + len + 1);
    free(dname);
 
    snprintf(flags, sizeof(flags), "quality=%d compress=%d",
             e->quality, e->compress);
-   r = evas_object_image_save(e->o, e->thumb_path, e->thumb_key, flags);
-
+   r = evas_object_image_save(e->o, buf, e->thumb_key, flags);
    if (!r)
      {
         ERR("could not save image: path=%s, key=%s", e->thumb_path,
             e->thumb_key);
         return EINA_FALSE;
      }
+   if (rename(buf, e->thumb_path) < 0)
+     {
+        ERR("could not rename image: path=%s, key=%s to path=%s",
+            buf, e->thumb_key, e->thumb_path);
+        return EINA_FALSE;
+     }
 
    return EINA_TRUE;
 }