mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-05-08 07:33:47 -04:00
[db] Fix concurrent index updates
If we are used to update the same repo at almost the same time, a race-condition can happen that tries to apply a diff to an already updated DB. We don't download anything while holding a DB transaction, so the download and check for the repo timestamp happens before we enter the transaction. However, we forgot to re-check the timestamp again within the transaction to be sure the DB state is still as expected.
This commit is contained in:
committed by
Torsten Grote
parent
632f55eb15
commit
cfaf9a5ad2
@@ -94,6 +94,12 @@ public class IndexV2Updater(
|
||||
file.inputStream().use { inputStream ->
|
||||
val repoDao = db.getRepositoryDao()
|
||||
db.runInTransaction {
|
||||
// ensure somebody else hasn't updated the repo in the meantime
|
||||
val currentTimestamp = repoDao.getRepository(repo.repoId)?.timestamp
|
||||
if (currentTimestamp != repo.timestamp) throw ConcurrentModificationException(
|
||||
"Repo timestamp expected ${repo.timestamp}, but was $currentTimestamp"
|
||||
)
|
||||
// still the expected timestamp, so go on processing...
|
||||
streamProcessor.process(repoVersion, inputStream) { i ->
|
||||
listener?.onUpdateProgress(repo, i, entryFile.numPackages)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user