From a6adc89700aea30db954ca7d6e9c073b754cdbfc Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 5 Mar 2020 16:09:42 +0900 Subject: Improve function to get storage id Change-Id: I2e52a2b5a86f58fe2e921bccbd192754b3915bdd Signed-off-by: Minje Ahn --- src/common/media-svc-storage.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c index 9903a71..127edc0 100755 --- a/src/common/media-svc-storage.c +++ b/src/common/media-svc-storage.c @@ -161,9 +161,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"); @@ -179,16 +176,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))) -- cgit v1.2.3