Sophie

Sophie

distrib > Mageia > 5 > x86_64 > by-pkgid > 07889aa078f2dd513f096cfda00d1d65 > files > 3

libfm-1.2.3-4.mga5.src.rpm

From ed02b1476ef477b9782a43b7aa2998e644ad6195 Mon Sep 17 00:00:00 2001
From: Andriy Grytsenko <andrej@rep.kiev.ua>
Date: Thu, 23 Oct 2014 19:10:42 +0300
Subject: [PATCH] [SF#902]Handle NULL returned by
 fm_mime_type_from_native_file() correctly.

---
 NEWS                    | 2 ++
 src/base/fm-file-info.c | 5 +++++
 src/base/fm-mime-type.c | 3 ++-
 src/base/fm-templates.c | 4 ++++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 6ad99f3..58ee98a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+* Fixed crash in templates on file that was deleted instantly after creation.
+
 Changes on 1.2.3 since 1.2.2:
 
 * Changed licence for libfm-extra and libfm components from GPL-2 to
diff --git a/src/base/fm-file-info.c b/src/base/fm-file-info.c
index 9072a14..fc3ca28 100644
--- a/src/base/fm-file-info.c
+++ b/src/base/fm-file-info.c
@@ -251,7 +251,12 @@ gboolean _fm_file_info_set_from_native_file(FmFileInfo* fi, const char* path,
                 fi->mime_type = fm_mime_type_from_file_name(fm_path_get_basename(fi->path));
         }
         else
+        {
             fi->mime_type = fm_mime_type_from_native_file(path, fm_path_get_basename(fi->path), &st);
+            if (G_UNLIKELY(fi->mime_type == NULL))
+                /* file might be deleted while we test it but we assume mime_type is not NULL */
+                fi->mime_type = fm_mime_type_from_name("application/octet-stream");
+        }
 
         if (get_fast) /* do rough estimation */
             fi->accessible = ((st.st_mode & S_IRUSR) == S_IRUSR);
diff --git a/src/base/fm-mime-type.c b/src/base/fm-mime-type.c
index e5ff140..1b28e48 100644
--- a/src/base/fm-mime-type.c
+++ b/src/base/fm-mime-type.c
@@ -127,7 +127,8 @@ FmMimeType* fm_mime_type_from_file_name(const char* ufile_name)
  * @base_name: file basename
  * @pstat: (allow-none): file atrributes
  *
- * Finds #FmMimeType descriptor for provided data.
+ * Finds #FmMimeType descriptor for provided data. If file does not exist
+ * then returns %NULL.
  *
  * Before 1.0.0 this API had name fm_mime_type_get_for_native_file.
  *
diff --git a/src/base/fm-templates.c b/src/base/fm-templates.c
index ea3526b..062b606 100644
--- a/src/base/fm-templates.c
+++ b/src/base/fm-templates.c
@@ -152,6 +152,10 @@ static FmMimeType *_fm_template_guess_mime_type(FmPath *path, FmMimeType *mime_t
     gchar *filename, *type, *url;
     GKeyFile *kf;
 
+    /* SF bug #902: if file was deleted instantly we get NULL here */
+    if (mime_type == NULL)
+        return NULL;
+
     /* if file is desktop entry then find the real template file path */
     if(mime_type != _fm_mime_type_get_application_x_desktop())
     {
-- 
2.1.3