@@ -706,6 +706,7 @@ nc_ctx_load_module(struct nc_session *session, const char *name, const char *rev
706706 const char * module_data = NULL ;
707707 struct ly_in * in ;
708708 LYS_INFORMAT format ;
709+ uint32_t temp_lo = LY_LOSTORE , * prev_lo ;
709710
710711 void (* free_module_data )(void * , void * ) = NULL ;
711712 struct clb_data_s clb_data ;
@@ -727,58 +728,57 @@ nc_ctx_load_module(struct nc_session *session, const char *name, const char *rev
727728 /* make the present module implemented and/or enable all its features */
728729 if (lys_set_implemented (* mod , features )) {
729730 ERR (session , "Failed to implement module \"%s\"." , (* mod )-> name );
730- ret = -1 ;
731+ return -1 ;
731732 }
732- } else {
733- /* missing implemented module, load it ... */
734- clb_data .has_get_schema = has_get_schema ;
735- clb_data .modules = modules ;
736- clb_data .session = session ;
737- clb_data .user_clb = user_clb ;
738- clb_data .user_data = user_data ;
739-
740- /* clear all the errors and just collect them for now */
741- ly_err_clean (session -> ctx , NULL );
742- ly_log_options (LY_LOSTORE );
743-
744- /* get module data */
745- retrieve_module_data (name , revision , & clb_data , & format , & module_data , & free_module_data );
746-
747- if (module_data ) {
748- /* set import callback */
749- ly_ctx_set_module_imp_clb (session -> ctx , retrieve_module_data_imp , & clb_data );
750-
751- /* parse the module */
752- ly_in_new_memory (module_data , & in );
753- lys_parse (session -> ctx , in , format , features , mod );
754- ly_in_free (in , 0 );
755- if (* free_module_data ) {
756- (* free_module_data )((char * )module_data , user_data );
757- }
733+ return 0 ;
734+ }
735+
736+ /* missing implemented module, load it ... */
737+ clb_data .has_get_schema = has_get_schema ;
738+ clb_data .modules = modules ;
739+ clb_data .session = session ;
740+ clb_data .user_clb = user_clb ;
741+ clb_data .user_data = user_data ;
742+
743+ /* clear all the errors and just collect them for now */
744+ ly_err_clean (session -> ctx , NULL );
745+ prev_lo = ly_temp_log_options (& temp_lo );
746+
747+ /* get module data */
748+ if (!retrieve_module_data (name , revision , & clb_data , & format , & module_data , & free_module_data )) {
749+ /* set import callback */
750+ ly_ctx_set_module_imp_clb (session -> ctx , retrieve_module_data_imp , & clb_data );
758751
759- ly_ctx_set_module_imp_clb (session -> ctx , NULL , NULL );
752+ /* parse the module */
753+ ly_in_new_memory (module_data , & in );
754+ lys_parse (session -> ctx , in , format , features , mod );
755+ ly_in_free (in , 0 );
756+ if (free_module_data ) {
757+ free_module_data ((char * )module_data , user_data );
760758 }
761759
762- /* restore logging options, then print errors on definite failure */
763- ly_log_options (LY_LOLOG | LY_LOSTORE_LAST );
764- if (!(* mod )) {
765- for (eitem = ly_err_first (session -> ctx ); eitem ; eitem = eitem -> next ) {
760+ ly_ctx_set_module_imp_clb (session -> ctx , NULL , NULL );
761+ }
762+
763+ /* restore logging options, then print errors on definite failure */
764+ ly_temp_log_options (prev_lo );
765+ if (!(* mod )) {
766+ for (eitem = ly_err_first (session -> ctx ); eitem ; eitem = eitem -> next ) {
767+ ly_err_print (session -> ctx , eitem );
768+ }
769+ ret = -1 ;
770+ } else {
771+ /* print only warnings */
772+ for (eitem = ly_err_first (session -> ctx ); eitem ; eitem = eitem -> next ) {
773+ if (eitem -> level == LY_LLWRN ) {
766774 ly_err_print (session -> ctx , eitem );
767775 }
768- ret = -1 ;
769- } else {
770- /* print only warnings */
771- for (eitem = ly_err_first (session -> ctx ); eitem ; eitem = eitem -> next ) {
772- if (eitem -> level == LY_LLWRN ) {
773- ly_err_print (session -> ctx , eitem );
774- }
775- }
776776 }
777-
778- /* clean the errors */
779- ly_err_clean (session -> ctx , NULL );
780777 }
781778
779+ /* clean the errors */
780+ ly_err_clean (session -> ctx , NULL );
781+
782782 return ret ;
783783}
784784
0 commit comments