@@ -953,28 +953,37 @@ static void response_download_cb(struct http_response *rsp, enum http_final_call
953953 }
954954 }
955955
956- if (rsp -> body_found ) {
957- body_data = rsp -> body_frag_start ;
958- body_len = rsp -> body_frag_len ;
956+ if (! rsp -> body_found ) {
957+ return ;
958+ }
959959
960- ret = flash_img_buffered_write (& hb_context -> flash_ctx , body_data , body_len ,
961- final_data == HTTP_DATA_FINAL );
962- if (ret < 0 ) {
963- LOG_ERR ("Failed to write flash: %d" , ret );
964- hb_context -> code_status = HAWKBIT_DOWNLOAD_ERROR ;
965- return ;
966- }
960+ body_data = rsp -> body_frag_start ;
961+ body_len = rsp -> body_frag_len ;
967962
968- #ifdef CONFIG_HAWKBIT_SAVE_PROGRESS
969- stream_flash_progress_save (& hb_context -> flash_ctx .stream , "hawkbit/flash_progress" );
970- #endif
963+ ret = flash_img_buffered_write (& hb_context -> flash_ctx , body_data , body_len ,
964+ final_data == HTTP_DATA_FINAL );
965+ if (ret < 0 ) {
966+ LOG_ERR ("Failed to write flash: %d" , ret );
967+ hb_context -> code_status = HAWKBIT_DOWNLOAD_ERROR ;
968+ return ;
971969 }
972970
971+ #if defined CONFIG_HAWKBIT_SAVE_PROGRESS && IS_EQ (CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL , 0 )
972+ stream_flash_progress_save (& hb_context -> flash_ctx .stream , "hawkbit/flash_progress" );
973+ #endif
974+
973975 hb_context -> dl .downloaded_size = flash_img_bytes_written (& hb_context -> flash_ctx );
974976
975977 downloaded = hb_context -> dl .downloaded_size * 100 / hb_context -> dl .file_size ;
976978
977979 if (downloaded != download_progress ) {
980+ #if defined CONFIG_HAWKBIT_SAVE_PROGRESS && !IS_EQ (CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL , 0 )
981+ if ((downloaded / CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL ) >
982+ (download_progress / CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL )) {
983+ stream_flash_progress_save (& hb_context -> flash_ctx .stream ,
984+ "hawkbit/flash_progress" );
985+ }
986+ #endif
978987 download_progress = downloaded ;
979988 LOG_DBG ("Downloaded: %u%% (%u / %u)" , download_progress ,
980989 hb_context -> dl .downloaded_size , hb_context -> dl .file_size );
0 commit comments