summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiyong.min <jiyong.min@samsung.com>2019-01-10 17:25:19 +0900
committerjiyong.min <jiyong.min@samsung.com>2019-01-10 17:38:39 +0900
commit475bd7f5abf354e2756703cef65c24a3cebff6a0 (patch)
tree20db9167b1d525ef77947d92ed3dd8f6090e96d8
parent5a7007c05f8a226df2b1eda4a09642ee104ae3d8 (diff)
downloadlibmm-fileinfo-475bd7f5abf354e2756703cef65c24a3cebff6a0.tar.gz
libmm-fileinfo-475bd7f5abf354e2756703cef65c24a3cebff6a0.tar.bz2
libmm-fileinfo-475bd7f5abf354e2756703cef65c24a3cebff6a0.zip
Add to check the file permission before mm_file access a file.submit/tizen/20190111.015801accepted/tizen/unified/20190114.060054
- error case Metadata-extractor did not return Permission denied. Change-Id: I5ef74a95dcca60e451d9c1e55aab67694f7f208e
-rw-r--r--[-rwxr-xr-x]include/mm_file_error.h1
-rw-r--r--[-rwxr-xr-x]mm_file.c32
2 files changed, 17 insertions, 16 deletions
diff --git a/include/mm_file_error.h b/include/mm_file_error.h
index d745fa7..0808785 100755..100644
--- a/include/mm_file_error.h
+++ b/include/mm_file_error.h
@@ -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
}
diff --git a/mm_file.c b/mm_file.c
index c501ef5..e4eadb5 100755..100644
--- 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;
}