Add to search download id from history db
authorJungki Kwak <jungki.kwak@samsung.com>
Wed, 5 Sep 2012 09:50:44 +0000 (18:50 +0900)
committerBang Kwang min <justine.bang@samsung.com>
Fri, 7 Sep 2012 02:11:42 +0000 (11:11 +0900)
[Title] Add to search download id from history db
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] If client restart the download after stoping it, the download id is exised at history db.

modified:   src/download-provider-db.c
modified:   src/download-provider-receiver.c

Change-Id: I7ce0c30b6cf0ea3c3ccf5f3ad629f364b8585601

src/download-provider-db.c
src/download-provider-receiver.c

index 5e63b3a..f72ca59 100644 (file)
@@ -1031,6 +1031,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
        if ((errorcode = sqlite3_step(stmt)) == SQLITE_ROW) {
                dbinfo = (download_dbinfo *) calloc(1, sizeof(download_dbinfo));
                dbinfo->requestid = requestid;
+               TRACE_DEBUG_INFO_MSG("found id from db [%d]", requestid);
                buffer = (char *)(sqlite3_column_text(stmt, 0));
                dbinfo->packagename = NULL;
                if (buffer) {
index ed72158..a2146b5 100644 (file)
@@ -392,12 +392,24 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                                                request_clientinfo->requestinfo->requestid);
                if (searchindex < 0) {
                        TRACE_DEBUG_INFO_MSG("Not Found Same Request ID");
-                       // Invalid id
-                       request_clientinfo->state = DOWNLOAD_STATE_FAILED;
-                       request_clientinfo->err = DOWNLOAD_ERROR_INVALID_PARAMETER;
-                       ipc_send_request_stateinfo(request_clientinfo);
-                       clear_clientinfo(request_clientinfo);
-                       return 0;
+                       /* Try to search history db */
+                       download_dbinfo *dbinfo = download_provider_db_history_get_info(
+                                       request_clientinfo->requestinfo->requestid);
+                       if (dbinfo == NULL) {
+                               /* Try to serach downloading db. The crashed job can not be uploaded to memory */
+                               dbinfo = download_provider_db_get_info(
+                                               request_clientinfo->requestinfo->requestid);
+                               if (dbinfo == NULL) {
+                                       /* Invalid id */
+                                       request_clientinfo->state = DOWNLOAD_STATE_FAILED;
+                                       request_clientinfo->err = DOWNLOAD_ERROR_INVALID_PARAMETER;
+                                       ipc_send_request_stateinfo(request_clientinfo);
+                                       clear_clientinfo(request_clientinfo);
+                                       return 0;
+                               }
+                       }
+                       download_provider_db_info_free(dbinfo);
+                       free(dbinfo);
                } else {        // found request id. // how to deal etag ?
                        // connect to slot.
                        TRACE_DEBUG_INFO_MSG("Found Same Request ID slot[%d]", searchindex);