Skip to content

Commit b36c3df

Browse files
committed
cleanup temporary migration file on cipher_migrate error
1 parent 78796fd commit b36c3df

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/crypto_impl.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,10 +1526,6 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
15261526
CODEC_TRACE("DETACH DATABASE called %d\n", rc);
15271527
if(rc != SQLITE_OK) goto cleanup;
15281528

1529-
rc = sqlite3OsDelete(db->pVfs, migrated_db_filename, 0);
1530-
CODEC_TRACE("deleted migration database: %d\n", rc);
1531-
if( rc!=SQLITE_OK ) goto handle_error;
1532-
15331529
sqlite3ResetAllSchemasOfConnection(db);
15341530
CODEC_TRACE("reset all schemas\n");
15351531

@@ -1544,6 +1540,11 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
15441540
CODEC_TRACE("An error occurred attempting to migrate the database - last error %d\n", rc);
15451541

15461542
cleanup:
1543+
if(migrated_db_filename) {
1544+
int del_rc = sqlite3OsDelete(db->pVfs, migrated_db_filename, 0);
1545+
CODEC_TRACE("deleted migration database: %d\n", del_rc);
1546+
}
1547+
15471548
if(pass) sqlcipher_free(pass, pass_sz);
15481549
if(attach_command) sqlcipher_free(attach_command, sqlite3Strlen30(attach_command));
15491550
if(migrated_db_filename) sqlcipher_free(migrated_db_filename, sqlite3Strlen30(migrated_db_filename));

test/sqlcipher-compatibility.test

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ do_test migrate-1.1.8-database-to-current-format {
10651065
}
10661066
} {ok 1}
10671067
db close
1068-
file delete -force test.db test.db-migrated test.db-journal
1068+
file delete -force test.db
10691069

10701070
do_test migrate-2-0-le-database-to-current-format {
10711071
file copy -force $sampleDir/sqlcipher-2.0-le-testkey.db test.db
@@ -1083,7 +1083,7 @@ do_test migrate-2-0-le-database-to-current-format {
10831083
}
10841084
} {ok 1}
10851085
db close
1086-
file delete -force test.db test.db-migrated test.db-journal
1086+
file delete -force test.db
10871087

10881088
do_test migrate-3-0-database-to-current-format {
10891089
file copy -force $sampleDir/sqlcipher-3.0-testkey.db test.db
@@ -1151,6 +1151,8 @@ do_test migrate-failure {
11511151
PRAGMA cipher_migrate;
11521152
}]
11531153
db close
1154+
1155+
lappend rc [file exists test.db-migrated]
11541156

11551157
sqlite_orig db test.db
11561158
lappend rc [execsql {
@@ -1159,9 +1161,9 @@ do_test migrate-failure {
11591161
PRAGMA cipher_compatibility = 3;
11601162
SELECT count(*) FROM sqlite_schema;
11611163
}]
1162-
} {{ok 1} {ok 1}}
1164+
} {{ok 1} 0 {ok 1}}
11631165
db close
1164-
file delete -force test.db test.db-migrated
1166+
file delete -force test.db
11651167

11661168
# leave database is a readable state after a
11671169
# a failed migration
@@ -1188,7 +1190,7 @@ do_test migrate-failure-readable {
11881190
}]
11891191
} {{ok 1} {1 {SQL logic error}} 0}
11901192
db close
1191-
file delete -force test.db test.db-migrated
1193+
file delete -force test.db
11921194

11931195
do_test key-database-by-name {
11941196
sqlite_orig db test.db

0 commit comments

Comments
 (0)