Fix bug 28/213928/3
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 16 Sep 2019 23:45:16 +0000 (08:45 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 17 Sep 2019 00:40:07 +0000 (09:40 +0900)
Add exception handling of requests for deleted directories

Change-Id: I1efe84058a340bf5d614b76a3948f8cbb9d1030f
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/media-util-register.c

index 5941e68..8d0bf4f 100755 (executable)
@@ -48,11 +48,20 @@ GArray *req_list;
 
 static int _check_dir_path(const char *dir_path, uid_t uid)
 {
-       ms_user_storage_type_e storage_type;
+       int ret = MS_MEDIA_ERR_NONE;
+       ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
+
+       /* TODO: Remove MS_MEDIA_ERR_INVALID_PATH type. Use MS_MEDIA_ERR_INVALID_PARAMETER instead. (gtest related issue) */
+       ret = ms_user_get_storage_type(uid, dir_path, &storage_type);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
 
-       MSAPI_RETV_IF(!g_file_test(dir_path, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INVALID_PATH);
+       /* dir_path can be a deleted path. */
+       if (g_file_test(dir_path, G_FILE_TEST_EXISTS)) {
+               /* Check only exist */
+               MSAPI_RETVM_IF(!g_file_test(dir_path, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INVALID_PATH, "Not a directory");
+       }
 
-       return ms_user_get_storage_type(uid, dir_path, &storage_type);
+       return MS_MEDIA_ERR_NONE;
 }
 
 /* receive message from media-server[function : ms_receive_message_from_scanner] */