elm_map: Make more robust elm_map
authorMichaël Bouchaud (yoz) <yoz@efl.so>
Mon, 25 Feb 2019 19:00:21 +0000 (14:00 -0500)
committerWonki Kim <wonki_.kim@samsung.com>
Fri, 8 Mar 2019 11:49:36 +0000 (20:49 +0900)
Summary:
Make more robust elm_map even if the user wipe is cache directory
or import an already filled tile cache.

@fix T7443

Reviewers: zmike, cedric

Reviewed By: zmike

Subscribers: thierry1970, cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T7443

Differential Revision: https://phab.enlightenment.org/D7617

src/lib/elementary/elm_map.c

index 92f722f..5d13cdd 100644 (file)
@@ -797,7 +797,7 @@ _download_job(void *data)
 
    EINA_LIST_REVERSE_FOREACH_SAFE(sd->download_list, l, ll, gi)
    {
-      Eina_Bool ret;
+      Eina_Bool ret, file_exists;
 
       if ((gi->g->zoom != sd->zoom) || !(_grid_item_in_viewport(gi)))
         {
@@ -807,21 +807,41 @@ _download_job(void *data)
       if (sd->download_num >= MAX_CONCURRENT_DOWNLOAD)
         return ECORE_CALLBACK_RENEW;
 
-      ret = ecore_file_download_full
-          (gi->url, gi->file, _downloaded_cb, NULL, gi, &(gi->job), sd->ua);
-
-      if ((!ret) || (!gi->job))
-        ERR("Can't start to download from %s to %s", gi->url, gi->file);
-      else
+      file_exists = ecore_file_exists(gi->file);
+      if (!file_exists)
         {
-           sd->download_list = eina_list_remove(sd->download_list, gi);
+           /* Check here if we can download into this directory even if this one
+              disappear due to some user black magic */
+           char *dir_path;
+           dir_path = ecore_file_dir_get(gi->file);
+           if (!ecore_file_exists(dir_path)) ecore_file_mkpath(dir_path);
+           free(dir_path);
+           ret = ecore_file_download_full
+              (gi->url, gi->file, _downloaded_cb, NULL, gi, &(gi->job), sd->ua);
+
+           if ((!ret) || (!gi->job))
+             {
+                ERR("Can't start to download from %s to %s", gi->url, gi->file);
+                continue;
+             }
            sd->try_num++;
            sd->download_num++;
+        }
+      sd->download_list = eina_list_remove(sd->download_list, gi);
+      efl_event_callback_legacy_call
+         (obj, ELM_MAP_EVENT_TILE_LOAD, NULL);
+      if (sd->download_num == 1)
+        edje_object_signal_emit(wd->resize_obj,
+                                "elm,state,busy,start", "elm");
+      if (file_exists)
+        {
+           /* It seem the file already exists, try to load it and let
+              _grid_item_update do his job. If this file isn't a image the func
+              will invalidate it and try to redownload it. */
+           _grid_item_update(gi);
+           gi->wsd->finish_num++;
            efl_event_callback_legacy_call
-             (obj, ELM_MAP_EVENT_TILE_LOAD, NULL);
-           if (sd->download_num == 1)
-             edje_object_signal_emit(wd->resize_obj,
-                                     "elm,state,busy,start", "elm");
+              ((gi->wsd)->obj, ELM_MAP_EVENT_TILE_LOADED, NULL);
         }
    }