Add to check the file permission before mm_file access a file. 25/197225/4 accepted/tizen/unified/20190114.060054 submit/tizen/20190111.015801
authorjiyong.min <jiyong.min@samsung.com>
Thu, 10 Jan 2019 08:25:19 +0000 (17:25 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 10 Jan 2019 08:38:39 +0000 (17:38 +0900)
- error case
Metadata-extractor did not return Permission denied.

Change-Id: I5ef74a95dcca60e451d9c1e55aab67694f7f208e

include/mm_file_error.h [changed mode: 0755->0644]
mm_file.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index d745fa7..0808785
@@ -31,6 +31,7 @@
 #define FILEINFO_ERROR_FILE_NOT_FOUND          -2      /**< Cannot find file */
 #define FILEINFO_ERROR_ATTR_NOT_EXIST          -3      /**< Attribute doesn't exist. */
 #define FILEINFO_ERROR_FILE_INTERNAL           -4      /**< Internal error */
+#define FILEINFO_ERROR_PERMISSION_DENIED       -5      /**< Permission denied */
 
 #ifdef __cplusplus
         }
old mode 100755 (executable)
new mode 100644 (file)
index c501ef5..e4eadb5
--- a/mm_file.c
+++ b/mm_file.c
@@ -292,15 +292,21 @@ static void _unload_dynamic_functions(MMFILE_FUNC_HANDLE *pHandle)
 static int
 _is_file_exist(const char *filename)
 {
-       int ret = 1;
+       int ret = FILEINFO_ERROR_NONE;
        if (filename) {
                const char *to_access = (strstr(filename, "file://") != NULL) ? filename + 7 : filename;
                ret = access(to_access, R_OK);
-               if (ret != 0) {
-                       debug_error(DEBUG, "file [%s] not found.\n", to_access);
+               if (ret < 0) {
+                       if (errno == EACCES || errno == EPERM) {
+                               debug_error(DEBUG, "Permission denied [%s]", to_access);
+                               ret = FILEINFO_ERROR_PERMISSION_DENIED;
+                       } else {
+                               debug_error(DEBUG, "Not exist file [%s]", to_access);
+                               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+                       }
                }
        }
-       return !ret;
+       return ret;
 }
 
 static int
@@ -836,8 +842,7 @@ int mm_file_create_tag_attrs(MMHandleType *tag_attrs, const char *filename)
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }
 
@@ -944,8 +949,7 @@ int mm_file_create_content_attrs(MMHandleType *contents_attrs, const char *filen
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }
 
@@ -1157,8 +1161,7 @@ int mm_file_get_stream_info(const char *filename, int *audio_stream_num, int *vi
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }
 
@@ -1221,8 +1224,7 @@ int mm_file_create_content_attrs_simple(MMHandleType *contents_attrs, const char
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }
 
@@ -1287,8 +1289,7 @@ int mm_file_create_content_attrs_safe(MMHandleType *contents_attrs, const char *
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }
 
@@ -1444,8 +1445,7 @@ int mm_file_check_uhqa(const char *filename, bool *is_uhqa)
        MM_FILE_SET_MEDIA_FILE_SRC(src, filename);
 
        ret = _is_file_exist(filename);
-       if (!ret) {
-               ret = FILEINFO_ERROR_FILE_NOT_FOUND;
+       if (ret != FILEINFO_ERROR_NONE) {
                goto END;
        }