efreet: check magic only for file which has size
authorWonguk Jeong <wonguk.jeong@samsung.com>
Thu, 17 Apr 2014 17:34:33 +0000 (19:34 +0200)
committerCedric Bail <cedric.bail@free.fr>
Thu, 17 Apr 2014 17:34:38 +0000 (19:34 +0200)
Summary:
Due to unnecessary magic checking, there was freezing in /proc in efm.
Proc file's st_size is zero, but, it's readable. therfore, it takes unnecessary time in magic checking. And, there is no need to check magic in case of 0 sized regular files as well.

Therefore, skip magic check in case of st_size is zero.

Fixes T1173

Test Plan: enlightenment -> file browser (efm) -> get int /proc --> check whether efm freezes or not

Reviewers: raster, cedric, zmike

CC: seoz, cedric
Maniphest Tasks: T1173

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

Signed-off-by: Cedric Bail <cedric.bail@free.fr>
src/lib/efreet/efreet_mime.c

index b21a75e..23d86cf 100644 (file)
@@ -1244,6 +1244,14 @@ efreet_mime_magic_check_priority(const char *file,
    const char *last_mime = NULL;
    int c;
    char v, buf[EFREET_MIME_MAGIC_BUFFER_SIZE];
+   struct stat s;
+
+#ifdef _WIN32
+   if (stat(file, &s) || s.st_size == 0)
+#else
+   if (lstat(file, &s) || s.st_size == 0)
+#endif
+      return NULL;
 
    f = fopen(file, "rb");
    if (!f) return NULL;