This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository entice.
View the commit online.
commit 670d6aaf9fcedbfdb314a7aa81444b33ac84232b
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Tue Dec 10 18:49:01 2024 +0100
fix thumb generation
---
meson.build | 2 +-
src/bin/entice_image.c | 2 +-
src/bin/entice_thumb.c | 8 ++-----
src/bin/entice_thumb_gen.c | 31 ++++++++++++++++++++++++++-
src/bin/entice_thumb_gen.h | 2 ++
src/bin/entice_thumb_util_file.c | 32 ++++++++++++++++++++++++++++
src/bin/entice_winlist.c | 45 +++++++++++++++++++++++++++++-----------
src/bin/meson.build | 2 +-
8 files changed, 102 insertions(+), 22 deletions(-)
diff --git a/meson.build b/meson.build
index ef735df..e4d9660 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@ project('entice', 'c',
version : '0.0.1',
license : 'BSD 2 clause',
default_options : [
- 'buildtype=plain',
+ 'buildtype=debug',
'warning_level=2'
],
meson_version : '>= 0.56',
diff --git a/src/bin/entice_image.c b/src/bin/entice_image.c
index ea10380..a588537 100644
--- a/src/bin/entice_image.c
+++ b/src/bin/entice_image.c
@@ -506,7 +506,7 @@ entice_image_memory_set(Evas_Object *obj, unsigned int *img, size_t size)
entice = evas_object_data_get(obj, "entice");
EINA_SAFETY_ON_NULL_RETURN(entice);
- if (!data || (size == 0))
+ if (!img || (size == 0))
return;
if (sd->timer_anim)
diff --git a/src/bin/entice_thumb.c b/src/bin/entice_thumb.c
index 4274743..e2a18a8 100644
--- a/src/bin/entice_thumb.c
+++ b/src/bin/entice_thumb.c
@@ -61,7 +61,6 @@ entice_thumb_sha1(const char *file, unsigned char dst[20])
LARGE_INTEGER size;
LARGE_INTEGER file_index;
LARGE_INTEGER creation;
- LARGE_INTEGER last_access;
LARGE_INTEGER last_write;
BOOL res;
@@ -83,19 +82,16 @@ entice_thumb_sha1(const char *file, unsigned char dst[20])
file_index.HighPart = info.nFileIndexHigh;
creation.LowPart = info.ftCreationTime.dwLowDateTime;
creation.HighPart = info.ftCreationTime.dwHighDateTime;
- last_access.LowPart = info.ftLastAccessTime.dwLowDateTime;
- last_access.HighPart = info.ftLastAccessTime.dwHighDateTime;
last_write.LowPart = info.ftLastWriteTime.dwLowDateTime;
last_write.HighPart = info.ftLastWriteTime.dwHighDateTime;
snprintf(buf, sizeof(buf),
- "%llu %llu %llu %llu %llu %llu %llu",
+ "%llu %llu %llu %llu %llu %llu",
(unsigned long long)(info.dwVolumeSerialNumber),
(unsigned long long)(info.dwFileAttributes),
(unsigned long long)(size.QuadPart),
(unsigned long long)(file_index.QuadPart),
(unsigned long long)(creation.QuadPart),
- (unsigned long long)(last_access.QuadPart),
(unsigned long long)(last_write.QuadPart));
#else
# ifdef STAT_NSEC
@@ -146,7 +142,7 @@ entice_thumb_find(const char *path)
eina_strbuf_append_char(buf, sha_str[0]);
eina_strbuf_append_char(buf, sha_str[1]);
eina_strbuf_append_char(buf, '/');
- eina_strbuf_append_length(buf, sha_str + 2, 38);
+ eina_strbuf_append_length(buf, sha_str, 40);
eina_strbuf_append(buf, ".eet");
return buf;
diff --git a/src/bin/entice_thumb_gen.c b/src/bin/entice_thumb_gen.c
index 2edc9f0..87bd4b9 100644
--- a/src/bin/entice_thumb_gen.c
+++ b/src/bin/entice_thumb_gen.c
@@ -61,8 +61,26 @@ _entice_thumb_output_open(const char *thumb)
return eet_open(buf, EET_FILE_MODE_WRITE);
}
+static void
+_entice_thumb_output_close(Eet_File *ef, const char *thumb)
+{
+ // close thumb file and atomically (not on Windows rename tmp file
+ // on top of target
+ char buf[PATH_MAX];
+ Eina_Bool ret;
+
+ eet_close(ef);
+ snprintf(buf, sizeof(buf), "%s.tmp", thumb);
+ // fix permissions on file to match parent dir
+#ifndef _WIN32
+ util_file_mode_parent_copy(buf, EINA_FALSE);
+#endif
+ ret = ecore_file_mv(buf, thumb);
+ fflush(stdout);
+}
+
EAPI_MAIN int
-main(int argc, char *argv[])
+elm_main(int argc, char *argv[])
{
unsigned char statsha1[20];
Eet_File *ef;
@@ -92,6 +110,7 @@ main(int argc, char *argv[])
elm_win_norender_push(win);
// stat orig file and store the state info we care about as a sha1 hash
+
if (!entice_thumb_sha1(path, statsha1))
exit(1);
@@ -121,8 +140,18 @@ main(int argc, char *argv[])
// otherwise handle as an image
else ret = thumb_image(ef, path, mime, thumb);
+ // write out the original file path so we could walk through all thumbs
+ // and find which thumbs no longer have an original file left
+ eet_write(ef, "orig/path", path, strlen(path), EET_COMPRESSION_LOW);
+ // write out our sha1 of the file stat info - quick and mostly right
+ // way to check if the thumb is up to date with file
+ eet_write(ef, "orig/stat/sha1", statsha1, 20, EET_COMPRESSION_NONE);
+ // done - finish file write and atomic rename
+ _entice_thumb_output_close(ef, thumb);
+
// if we failed to generate the thumb - delete what we were building
if (ret != 0) unlink(thumb);
return ret;
}
+ELM_MAIN()
diff --git a/src/bin/entice_thumb_gen.h b/src/bin/entice_thumb_gen.h
index 59910e4..3347156 100644
--- a/src/bin/entice_thumb_gen.h
+++ b/src/bin/entice_thumb_gen.h
@@ -89,6 +89,8 @@ void thumb_url_bin_get(const char *url,
void (*cb)(void *data, const void *result, size_t size),
const void *data);
+void util_file_mode_parent_copy(const char *file, Eina_Bool is_dir);
+
static inline Eina_Bool
_entice_thumb_check_image(const char *mime)
{
diff --git a/src/bin/entice_thumb_util_file.c b/src/bin/entice_thumb_util_file.c
new file mode 100644
index 0000000..5452db9
--- /dev/null
+++ b/src/bin/entice_thumb_util_file.c
@@ -0,0 +1,32 @@
+#ifndef _WIN32
+
+#include <Eina.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+void
+util_file_mode_parent_copy(const char *file, Eina_Bool is_dir)
+{
+ struct stat st;
+ char *s, *dir_parent = strdup(file);
+
+ if (!dir_parent) return;
+ s = strrchr(dir_parent, '/');
+ if (!s) goto err;
+ s[1] = '\0'; // get parent dir by truncating after /
+ if (lstat(dir_parent, &st) == 0)
+ { // copy the parent dir mode to the child file given
+ chown(file, st.st_uid, st.st_gid);
+ // if it's not a dir - filter out execute mode
+ if (!is_dir)
+ st.st_mode &= S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+ chmod(file, st.st_mode);
+ }
+err:
+ free(dir_parent);
+}
+
+#endif
diff --git a/src/bin/entice_winlist.c b/src/bin/entice_winlist.c
index 09bc277..91b9871 100644
--- a/src/bin/entice_winlist.c
+++ b/src/bin/entice_winlist.c
@@ -79,6 +79,14 @@ entice_winlist_genlist_sel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
/* data, obj, event_info, elm_genlist_item_index_get(event_info)); */
}
+static const char *
+_entice_winlist_mime_get(const char *file)
+{
+ if (eina_fnmatch("*.edj", file, EINA_FNMATCH_CASEFOLD))
+ return "application/x-edje";
+ return efreet_mime_type_get(file);
+}
+
static Evas_Object *
entice_winlist_genlist_content_get(void *data, Evas_Object *obj, const char *part)
{
@@ -97,9 +105,6 @@ entice_winlist_genlist_content_get(void *data, Evas_Object *obj, const char *par
Ecore_Timer *timer;
Eina_Strbuf *buf;
- printf(" $$ '%s'\n", d->path);
- fflush(stdout);
-
// TODO: check if d->path needs thumbnail (image, edje, ...)
buf = entice_thumb_find(d->path);
@@ -110,18 +115,14 @@ entice_winlist_genlist_content_get(void *data, Evas_Object *obj, const char *par
thumb = eina_strbuf_string_get(buf);
- printf(" ** 1: '%s'\n", thumb);
- fflush(stdout);
ef = eet_open(thumb, EET_FILE_MODE_READ);
eina_strbuf_free(buf);
+ buf = NULL;
if (ef)
{
unsigned char sha[20];
- printf(" ** 2: '%s'\n", eet_file_get(ef));
- fflush(stdout);
-
- /* thumb file exists - check meta data */
+ /* thumb file exists - check meta data */
if (entice_thumb_sha1(d->path, sha))
{
char *sha_orig;
@@ -143,8 +144,28 @@ entice_winlist_genlist_content_get(void *data, Evas_Object *obj, const char *par
}
else
{
- printf("thumb file does not exist -> must create it\n");
- fflush(stdout);
+ Eina_Strbuf *cmd;
+
+ cmd = eina_strbuf_new();
+ if (cmd)
+ {
+ Ecore_Exe *exe;
+
+ eina_strbuf_append(cmd, PACKAGE_BIN_DIR);
+ eina_strbuf_append(cmd, "/entice_thumb_gen");
+#if _WIN32
+ eina_strbuf_append(cmd, ".exe");
+#endif
+ eina_strbuf_append_char(cmd, ' ');
+ eina_strbuf_append(cmd, d->path);
+ eina_strbuf_append_char(cmd, ' ');
+ eina_strbuf_append(cmd, _entice_winlist_mime_get(d->path));
+ eina_strbuf_append_char(cmd, ' ');
+ eina_strbuf_append(cmd, thumb);
+ exe = ecore_exe_run(eina_strbuf_string_get(cmd), NULL);
+ eina_strbuf_free(cmd);
+ cmd = NULL;
+ }
}
}
@@ -217,7 +238,7 @@ hints_changed(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_inf
evas_object_size_hint_min_get(obj, &w, &h);
printf(" *** hints min %d %d\n", w, h);
/* evas_object_size_hint_min_set(data, w, h); */
-
+
evas_object_size_hint_max_get(obj, &w, &h);
printf(" *** hints min %d %d\n", w, h);
/* evas_object_size_hint_max_set(data, w, h); */
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 2f142e7..5d4fccb 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -4,6 +4,7 @@
entice_thumb_gen_src = files([
'entice_thumb.c',
'entice_thumb_gen.c',
+ 'entice_thumb_util_file.c',
'entice_thumb_util_img.c',
'entice_thumb_util_search.c',
'entice_thumb_util_url.c',
@@ -13,7 +14,6 @@ entice_thumb_gen_src = files([
'thumb_music.c',
'thumb_paged.c',
'thumb_video.c',
-
])
entice_thumb_gen = executable('entice_thumb_gen', entice_thumb_gen_src,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.