@@ -263,7 +263,7 @@ cmd_data_opt(struct yl_opt *yo, const char *cmdline, char ***posv, int *posc)
263263 return 1 ;
264264 }
265265 break ;
266- case 'k' : /* --ext-id */
266+ case 'k' : /* --ext-inst */
267267 if (parse_ext_string (optarg , yo )) {
268268 YLMSG_E ("Invalid name of extension instance." );
269269 return 1 ;
@@ -642,37 +642,37 @@ parse_input_by_type(struct ly_ctx *ctx, enum lyd_type type, struct cmdline_file
642642 * @param[in] ctx libyang context with schema.
643643 * @param[in] yo context for yanglint.
644644 * @param[in] input_f Data input file.
645+ * @param[out] tree Extension data tree.
645646 * @param[in] oper_tree operational data tree.
646647 * @return LY_ERR value.
647648 */
648649static LY_ERR
649- parse_extension_instance (struct ly_ctx * ctx , struct yl_opt * yo , struct cmdline_file * input_f , struct lyd_node * oper_tree )
650+ parse_extension_instance (struct ly_ctx * ctx , struct yl_opt * yo , struct cmdline_file * input_f , struct lyd_node * * tree , struct lyd_node * oper_tree )
650651{
651652
652653 LY_ERR ret = LY_SUCCESS ;
653- struct lyd_node * tree ;
654+ struct lyd_node * tree_copy ;
654655
655656 if (find_extension (ctx , yo )) {
656657 YLMSG_E ("Extension '%s:%s:%s' not found in module." , yo -> mod_name , yo -> name , yo -> argument );
657658 return LY_ENOTFOUND ;
658659 }
659660
660- if ((ret = lyd_parse_ext_data (yo -> ext , NULL , input_f -> in , input_f -> format , LYD_PARSE_ONLY , 0 , & tree ))) {
661+ if ((ret = lyd_parse_ext_data (yo -> ext , NULL , input_f -> in , input_f -> format , LYD_PARSE_ONLY , 0 , tree ))) {
661662 YLMSG_E ("Parsing of extension data failed." )
662663 return ret ;
663664 }
664- if (oper_tree ) {
665- lyd_insert_sibling (tree , oper_tree , & tree );
666- }
667665
668- ret = lyd_validate_all ( & tree , ctx , yo -> data_validate_options , NULL );
666+ lyd_dup_siblings ( * tree , NULL , LYD_DUP_RECURSIVE , & tree_copy );
669667
670- if (yo -> data_out_format ) {
671- lyd_print_all ( yo -> out , tree , yo -> data_out_format , yo -> data_print_options );
668+ if (oper_tree ) {
669+ lyd_insert_sibling ( tree_copy , oper_tree , & tree_copy );
672670 }
673671
672+ ret = lyd_validate_all (& tree_copy , ctx , yo -> data_validate_options , NULL );
673+
674674 if (!yo -> data_operational .in ) {
675- lyd_free_all (tree );
675+ lyd_free_all (tree_copy );
676676 }
677677
678678 yo -> data_ext = 0 ;
@@ -700,7 +700,7 @@ cmd_data_process(struct ly_ctx *ctx, struct yl_opt *yo)
700700 struct cmdline_file * input_f = (struct cmdline_file * )yo -> data_inputs .objs [u ];
701701
702702 if (yo -> data_ext ) {
703- ret = parse_extension_instance (ctx , yo , input_f , oper_tree );
703+ ret = parse_extension_instance (ctx , yo , input_f , & tree , oper_tree );
704704 } else {
705705 ret = parse_input_by_type (ctx , yo -> data_type , input_f , yo -> data_parse_options , yo -> data_validate_options , & tree , & op , & yo -> reply_rpc );
706706 }
0 commit comments