Browse Source

sr_discard_changes() if sr_apply_changes() is failed

Serj Kalichev 8 months ago
parent
commit
b9093b0405
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/syms.c

+ 7 - 1
src/syms.c

@@ -367,6 +367,7 @@ int srp_set(kcontext_t *context)
 	}
 
 	if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
+		sr_discard_changes(sess);
 		srp_error(sess, ERRORMSG "Can't apply changes\n");
 		goto cleanup;
 	}
@@ -418,6 +419,7 @@ int srp_del(kcontext_t *context)
 	}
 
 	if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
+		sr_discard_changes(sess);
 		srp_error(sess, ERRORMSG "Can't apply changes\n");
 		goto err;
 	}
@@ -469,6 +471,7 @@ int srp_edit(kcontext_t *context)
 	}
 
 	if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
+		sr_discard_changes(sess);
 		srp_error(sess, ERRORMSG "Can't apply changes\n");
 		goto err;
 	}
@@ -640,6 +643,7 @@ int srp_insert(kcontext_t *context)
 	}
 
 	if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
+		sr_discard_changes(sess);
 		srp_error(sess, ERRORMSG "Can't apply changes\n");
 		goto err;
 	}
@@ -930,8 +934,10 @@ int srp_deactivate(kcontext_t *context)
 	if (sr_has_changes(sess))
 		fprintf(stderr, ERRORMSG "Has changes\n");
 
-	if (sr_apply_changes(sess, 0) != SR_ERR_OK)
+	if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
+		sr_discard_changes(sess);
 		srp_error(sess, ERRORMSG "Can't apply changes\n");
+	}
 	sr_release_data(data);
 
 	if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {