extra: do not use the same request field for cache and download
otherwise we could get a racecondition between two preview_get calls and preview_download.
This commit is contained in:
parent
fe62d65bca
commit
b62d34180c
|
@ -29,6 +29,7 @@ static Eina_Bool extra_request_may_override(Extra_Request *req, Extra_Progress *
|
|||
typedef struct {
|
||||
Extra_Theme theme;
|
||||
Extra_Request *preview;
|
||||
Extra_Request *cache_preview;
|
||||
Extra_Request *main;
|
||||
} Extra_Theme_Private;
|
||||
|
||||
|
@ -86,6 +87,7 @@ _fill_themes(Eina_Strbuf *buf)
|
|||
typedef struct {
|
||||
Extra_Background background;
|
||||
Extra_Request *preview;
|
||||
Extra_Request *cache_preview;
|
||||
Extra_Request *main;
|
||||
} Extra_Background_Private;
|
||||
|
||||
|
@ -394,6 +396,7 @@ Extra_Progress p = {NULL, NULL, NULL};
|
|||
EAPI char*
|
||||
extra_theme_preview_get(Extra_Theme *theme)
|
||||
{
|
||||
char *src, *dst;
|
||||
char *local;
|
||||
Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme);
|
||||
|
||||
|
@ -408,7 +411,16 @@ extra_theme_preview_get(Extra_Theme *theme)
|
|||
}
|
||||
else
|
||||
{
|
||||
extra_theme_preview_download(&p, theme);
|
||||
if (!priv->cache_preview)
|
||||
{
|
||||
src = _extra_preview_remote_generate("themes", theme->id);
|
||||
dst = _extra_preview_local_generate("themes", theme->id, theme->version);
|
||||
|
||||
extra_file_cache_download(&p, src, dst, &priv->cache_preview);
|
||||
|
||||
free(src);
|
||||
free(dst);
|
||||
}
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
@ -714,6 +726,7 @@ extra_background_download(Extra_Progress *progress, Extra_Background *background
|
|||
EAPI char*
|
||||
extra_background_preview_get(Extra_Background *background)
|
||||
{
|
||||
char *src, *dst;
|
||||
char *local;
|
||||
Extra_Background_Private *priv = (Extra_Background_Private*) background;
|
||||
|
||||
|
@ -727,7 +740,16 @@ extra_background_preview_get(Extra_Background *background)
|
|||
}
|
||||
else
|
||||
{
|
||||
extra_background_preview_download(&p, background);
|
||||
if (!priv->cache_preview)
|
||||
{
|
||||
src = _extra_preview_remote_generate("backgrounds", background->id);
|
||||
dst = _extra_preview_local_generate("backgrounds", background->id, background->version);
|
||||
|
||||
extra_file_cache_download(&p, src, dst, &priv->cache_preview);
|
||||
|
||||
free(src);
|
||||
free(dst);
|
||||
}
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
|
|
@ -286,8 +286,8 @@ end:
|
|||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
void
|
||||
extra_file_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req)
|
||||
static Extra_Download_Job*
|
||||
_extra_file_job_new(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req)
|
||||
{
|
||||
Extra_Download_Job *job;
|
||||
|
||||
|
@ -297,30 +297,41 @@ extra_file_download(Extra_Progress *progress, const char *from, const char *to,
|
|||
job->to = strdup(to);
|
||||
job->from = strdup(from);
|
||||
|
||||
if (ecore_file_exists(to))
|
||||
{
|
||||
char path[PATH_MAX], *dir;
|
||||
const char *file;
|
||||
|
||||
file = ecore_file_file_get(to);
|
||||
dir = ecore_file_dir_get(to);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/cache-%s", dir, file);
|
||||
ecore_file_remove(path);
|
||||
ecore_file_download(from, path,
|
||||
NULL,
|
||||
_download_check_progress_cb,
|
||||
job, &job->cache);
|
||||
|
||||
free(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecore_file_download(from, to,
|
||||
_download_complete_cb,
|
||||
_download_progress_cb,
|
||||
job, &job->full);
|
||||
}
|
||||
if (req)
|
||||
*req = &job->req;
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
void
|
||||
extra_file_cache_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req)
|
||||
{
|
||||
Extra_Download_Job *job = _extra_file_job_new(progress, from, to, req);
|
||||
|
||||
char path[PATH_MAX], *dir;
|
||||
const char *file;
|
||||
|
||||
file = ecore_file_file_get(to);
|
||||
dir = ecore_file_dir_get(to);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/cache-%s", dir, file);
|
||||
ecore_file_remove(path);
|
||||
ecore_file_download(from, path,
|
||||
NULL,
|
||||
_download_check_progress_cb,
|
||||
job, &job->cache);
|
||||
|
||||
free(dir);
|
||||
}
|
||||
|
||||
void
|
||||
extra_file_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req)
|
||||
{
|
||||
Extra_Download_Job *job = _extra_file_job_new(progress, from, to, req);
|
||||
|
||||
ecore_file_download(from, to,
|
||||
_download_complete_cb,
|
||||
_download_progress_cb,
|
||||
job, &job->full);
|
||||
|
||||
}
|
||||
|
|
|
@ -61,5 +61,5 @@ Eina_List* extra_json_to_list(Extra_Json_To_List_Template *tmp, Eina_Strbuf *buf
|
|||
void extra_json_list_part_free(Extra_Json_To_List_Template *tmp, void *data);
|
||||
|
||||
void extra_file_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req);
|
||||
|
||||
void extra_file_cache_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue