Improve function to get storage id 34/226834/1
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 5 Mar 2020 07:09:42 +0000 (16:09 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Fri, 6 Mar 2020 01:30:17 +0000 (01:30 +0000)
Change-Id: I2e52a2b5a86f58fe2e921bccbd192754b3915bdd
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/media-svc-storage.c

index 50cc443..bc459af 100755 (executable)
@@ -216,9 +216,6 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3_stmt *sql_stmt = NULL;
        char *sql = NULL;
-       char *storage_path = NULL;
-       char *remain_path = NULL;
-       int remain_len = 0;
        char *internal_path = NULL;
 
        media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
@@ -234,16 +231,9 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage
 
        SAFE_FREE(internal_path);
 
-       remain_path = strstr(path + (STRING_VALID(MEDIA_ROOT_PATH_USB) ? strlen(MEDIA_ROOT_PATH_USB) : 0) + 1, "/");
-       if (remain_path != NULL)
-               remain_len = strlen(remain_path);
-
-       storage_path = strndup(path, strlen(path) - remain_len);
-
-       sql = sqlite3_mprintf("SELECT storage_id FROM '%q' WHERE validity=1 AND storage_path = '%q'", MEDIA_SVC_DB_TABLE_STORAGE, storage_path);
+       sql = sqlite3_mprintf("SELECT storage_id FROM %q WHERE validity=1 AND instr(%Q, storage_path)", MEDIA_SVC_DB_TABLE_STORAGE, path);
 
        ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-       SAFE_FREE(storage_path);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))