exclusive mode lock on tpk_save ENGINE-581
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 25 Jun 2019 13:26:54 +0200
branchENGINE-581
changeset 386948fe5cb98a93
parent 3867 3de2673a6724
child 3870 018251280dbf
exclusive mode lock on tpk_save
src/pgp_sequoia.c
test/src/engine_tests/IOS1664Tests.cc
     1.1 --- a/src/pgp_sequoia.c	Fri Jun 21 17:10:20 2019 +0200
     1.2 +++ b/src/pgp_sequoia.c	Tue Jun 25 13:26:54 2019 +0200
     1.3 @@ -697,6 +697,17 @@
     1.4      char *email = NULL;
     1.5      char *name = NULL;
     1.6  
     1.7 +    int int_result = sqlite3_exec(
     1.8 +        session->key_db,
     1.9 +        "PRAGMA locking_mode=EXCLUSIVE;\n"
    1.10 +        ,
    1.11 +        NULL,
    1.12 +        NULL,
    1.13 +        NULL
    1.14 +    );
    1.15 +    if (int_result != SQLITE_OK)
    1.16 +        status = PEP_UNKNOWN_DB_ERROR;
    1.17 +
    1.18      sqlite3_stmt *stmt = session->sq_sql.begin_transaction;
    1.19      int sqlite_result = Sqlite3_step(stmt);
    1.20      sqlite3_reset(stmt);
    1.21 @@ -852,6 +863,18 @@
    1.22                        sqlite3_errmsg(session->key_db));
    1.23      }
    1.24  
    1.25 +    int int_result = sqlite3_exec(
    1.26 +        session->key_db,
    1.27 +        "PRAGMA locking_mode=NORMAL;\n"
    1.28 +        ,
    1.29 +        NULL,
    1.30 +        NULL,
    1.31 +        NULL
    1.32 +    );
    1.33 +    // FIXME: what to do here? Don't want to override status.
    1.34 +    // if (int_result != SQLITE_OK)
    1.35 +    //     status = PEP_UNKNOWN_DB_ERROR;
    1.36 +
    1.37      T("(%s) -> %s", fpr, pEp_status_to_string(status));
    1.38  
    1.39      free(email);
     2.1 --- a/test/src/engine_tests/IOS1664Tests.cc	Fri Jun 21 17:10:20 2019 +0200
     2.2 +++ b/test/src/engine_tests/IOS1664Tests.cc	Tue Jun 25 13:26:54 2019 +0200
     2.3 @@ -48,12 +48,23 @@
     2.4      
     2.5      pEp_identity* you = new_identity("superxat@gmail.com", NULL, NULL, NULL);
     2.6      
     2.7 +    // N.B. while obviously it would be better to write the test expecting us to 
     2.8 +    // accept the key, I'm actually testing that we don't get the wrong status
     2.9 +    // based on the presumption of rejection
    2.10 +    
    2.11      message* out_msg = new_message(PEP_dir_outgoing);
    2.12      out_msg->from = me;
    2.13      out_msg->to = new_identity_list(you);
    2.14      out_msg->shortmsg = strdup("Hussidente 2020!");
    2.15      out_msg->longmsg = strdup("A Huss in every office!");
    2.16      
    2.17 +    status = identity_rating(session, out_msg->from, &rating);
    2.18 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.19 +    TEST_ASSERT_MSG(rating == PEP_rating_trusted_and_anonymized, tl_rating_string(rating));
    2.20 +    status = identity_rating(session, out_msg->to->ident, &rating);
    2.21 +    TEST_ASSERT_MSG(status == PEP_KEY_NOT_FOUND, tl_status_string(status));
    2.22 +    TEST_ASSERT_MSG(rating == PEP_rating_undefined, tl_rating_string(rating));
    2.23 +
    2.24      status = outgoing_message_rating(session, out_msg, &rating);
    2.25      TEST_ASSERT(rating == PEP_rating_unencrypted);
    2.26