diff options
author | Minje Ahn <minje.ahn@samsung.com> | 2017-07-07 16:18:45 +0900 |
---|---|---|
committer | Minje Ahn <minje.ahn@samsung.com> | 2017-07-10 10:57:39 +0900 |
commit | 19fcd8fbf7baff560bc70737d42a5c3ea26887bb (patch) | |
tree | 479c5df9bcf968725ad70ae4bf978b95b168d66f /src/util | |
parent | c5ad1ae3877f3578a820bedbf253c7dd72e8e382 (diff) | |
download | libmedia-thumbnail-19fcd8fbf7baff560bc70737d42a5c3ea26887bb.tar.gz libmedia-thumbnail-19fcd8fbf7baff560bc70737d42a5c3ea26887bb.tar.bz2 libmedia-thumbnail-19fcd8fbf7baff560bc70737d42a5c3ea26887bb.zip |
Remove double check
Change-Id: I170b95a4f6a60119d53a33d1ed602b50a0cd31ab
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'src/util')
-rwxr-xr-x | src/util/media-thumb-db.c | 95 |
1 files changed, 20 insertions, 75 deletions
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c index a572734..6f20e12 100755 --- a/src/util/media-thumb-db.c +++ b/src/util/media-thumb-db.c @@ -46,23 +46,14 @@ int _media_thumb_get_thumb_path_wh_from_db(sqlite3 *handle, char *query_string = NULL; sqlite3_stmt *stmt = NULL; - if (handle == NULL) { - thumb_err("DB handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } + thumb_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "DB handle is NULL"); + thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path"); query_string = sqlite3_mprintf(SELECT_THUMB_BY_PATH, origin_path); - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } + thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed"); thumb_dbg_slog("Query: %s", query_string); + err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL); SQLITE3_SAFE_FREE(query_string); if (SQLITE_OK != err) { @@ -92,42 +83,6 @@ int _media_thumb_get_thumb_path_wh_from_db(sqlite3 *handle, return MS_MEDIA_ERR_NONE; } -int _media_thumb_update_thumb_path_wh_to_db(const char *origin_path, - char *thumb_path, - int width, - int height, - uid_t uid) -{ - int err = MS_MEDIA_ERR_NONE; - char *query_string = NULL; - - if (!STRING_VALID(origin_path)) { - thumb_err("Invalid origin_path"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - if (width > 0 && height > 0) - query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, origin_path); - else - query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path); - - if (!STRING_VALID(query_string)) { - thumb_err("Memory allocation is failed"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - err = media_db_request_update_db(query_string, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("media_db_request_update_db failed : %d", err); - } else { - thumb_dbg("Query success"); - } - - SQLITE3_SAFE_FREE(query_string); - - return err; -} - int _media_thumb_db_connect(uid_t uid) { int err = MS_MEDIA_ERR_NONE; @@ -155,26 +110,15 @@ int _media_thumb_db_disconnect() return err; } -int _media_thumb_get_thumb_from_db_with_size(const char *origin_path, - char *thumb_path, - int max_length, - int *width, - int *height) +int _media_thumb_get_thumb_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *width, int *height) { int err = MS_MEDIA_ERR_NONE; int orig_w = 0; int orig_h = 0; err = _media_thumb_get_thumb_path_wh_from_db(db_handle, origin_path, thumb_path, max_length, &orig_w, &orig_h); - if (err != MS_MEDIA_ERR_NONE) { - thumb_warn("Original path doesn't exist in DB"); - return err; - } - - if (strlen(thumb_path) == 0) { - thumb_warn("thumb path doesn't exist in DB"); - return MS_MEDIA_ERR_INTERNAL; - } + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Original path doesn't exist in DB"); + thumb_retvm_if(!STRING_VALID(thumb_path), MS_MEDIA_ERR_INTERNAL, "[No-error] thumb path doesn't exist in DB"); thumb_dbg_slog("Thumb path in DB is %s", thumb_path); @@ -190,22 +134,23 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path, return MS_MEDIA_ERR_NONE; } -int _media_thumb_update_db(const char *origin_path, - char *thumb_path, - int width, - int height, - uid_t uid) +int _media_thumb_update_db(const char *origin_path, char *thumb_path, int width, int height, uid_t uid) { int err = MS_MEDIA_ERR_NONE; + char *query_string = NULL; - err = _media_thumb_update_thumb_path_wh_to_db(origin_path, thumb_path, width, height, uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); - return err; - } + thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path"); + + if (width > 0 && height > 0) + query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, origin_path); + else + query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path); - thumb_dbg("_media_thumb_update_db success"); + thumb_retvm_if(!STRING_VALID(query_string), MS_MEDIA_ERR_OUT_OF_MEMORY, "Memory allocation is failed"); - return MS_MEDIA_ERR_NONE; + err = media_db_request_update_db(query_string, uid); + SQLITE3_SAFE_FREE(query_string); + + return err; } |