introduce updateTrustDb to use instead of a full consolidate
This commit is contained in:
@@ -18,15 +18,17 @@
|
||||
package org.sufficientlysecure.keychain.operations;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.sufficientlysecure.keychain.BuildConfig;
|
||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.UpdateTrustResult;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
@@ -92,10 +94,11 @@ public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel>
|
||||
}
|
||||
}
|
||||
|
||||
if (!BuildConfig.DEBUG && isSecret && success > 0) {
|
||||
if (isSecret && success > 0) {
|
||||
log.add(LogType.MSG_DEL_CONSOLIDATE, 1);
|
||||
ConsolidateResult sub = mKeyWritableRepository.consolidateDatabaseStep1(mProgressable);
|
||||
log.add(sub, 2);
|
||||
UpdateTrustResult sub = mKeyWritableRepository.updateTrustDb(
|
||||
Collections.singletonList(masterKeyIds[0]), mProgressable);
|
||||
// log.add(sub, 2);
|
||||
}
|
||||
|
||||
int result = DeleteResult.RESULT_OK;
|
||||
|
||||
@@ -39,19 +39,19 @@ import android.support.annotation.Nullable;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.FacebookKeyserverClient;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverClient;
|
||||
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserverClient;
|
||||
import org.sufficientlysecure.keychain.keyimport.KeyserverClient;
|
||||
import org.sufficientlysecure.keychain.keyimport.KeyserverClient.QueryNotFoundException;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.UpdateTrustResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
@@ -155,7 +155,8 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
return new ImportKeyResult(ImportKeyResult.RESULT_FAIL_NOTHING, log);
|
||||
}
|
||||
|
||||
int newKeys = 0, updatedKeys = 0, missingKeys = 0, badKeys = 0, secret = 0;
|
||||
int newKeys = 0, updatedKeys = 0, missingKeys = 0, badKeys = 0;
|
||||
ArrayList<Long> secretMasterKeyIds = new ArrayList<>();
|
||||
ArrayList<Long> importedMasterKeyIds = new ArrayList<>();
|
||||
|
||||
ArrayList<CanonicalizedKeyRing> canKeyRings = new ArrayList<>();
|
||||
@@ -223,7 +224,8 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
if (key.isSecret()) {
|
||||
result = mKeyWritableRepository.saveSecretKeyRing(key, canKeyRings, skipSave);
|
||||
} else {
|
||||
result = mKeyWritableRepository.savePublicKeyRing(key, entry.getExpectedFingerprint(), canKeyRings, skipSave);
|
||||
result = mKeyWritableRepository.savePublicKeyRing(key, entry.getExpectedFingerprint(), canKeyRings,
|
||||
false, skipSave);
|
||||
}
|
||||
}
|
||||
if (!result.success()) {
|
||||
@@ -235,7 +237,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
} else {
|
||||
newKeys += 1;
|
||||
if (key.isSecret()) {
|
||||
secret += 1;
|
||||
secretMasterKeyIds.add(key.getMasterKeyId());
|
||||
}
|
||||
importedMasterKeyIds.add(key.getMasterKeyId());
|
||||
}
|
||||
@@ -260,13 +262,13 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
// synchronized on mProviderHelper to prevent
|
||||
// https://github.com/open-keychain/open-keychain/issues/1221 since a consolidate deletes
|
||||
// and re-inserts keys, which could conflict with a parallel db key update
|
||||
if (!skipSave && (secret > 0)) {
|
||||
if (!skipSave && !secretMasterKeyIds.isEmpty()) {
|
||||
setPreventCancel();
|
||||
ConsolidateResult result;
|
||||
UpdateTrustResult result;
|
||||
synchronized (mKeyRepository) {
|
||||
result = mKeyWritableRepository.consolidateDatabaseStep1(progressable);
|
||||
result = mKeyWritableRepository.updateTrustDb(secretMasterKeyIds, progressable);
|
||||
}
|
||||
log.add(result, 1);
|
||||
// log.add(result, 1);
|
||||
}
|
||||
|
||||
// Special: make sure new data is synced into contacts
|
||||
@@ -320,7 +322,8 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
||||
}
|
||||
|
||||
ImportKeyResult result = new ImportKeyResult(
|
||||
resultType, log, newKeys, updatedKeys, missingKeys, badKeys, secret, importedMasterKeyIdsArray);
|
||||
resultType, log, newKeys, updatedKeys, missingKeys, badKeys, secretMasterKeyIds.size(),
|
||||
importedMasterKeyIdsArray);
|
||||
|
||||
result.setCanonicalizedKeyRings(canKeyRings);
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.operations.results;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
|
||||
public class UpdateTrustResult extends OperationResult {
|
||||
|
||||
public UpdateTrustResult(int result, OperationLog log) {
|
||||
super(result, log);
|
||||
}
|
||||
|
||||
/** Construct from a parcel - trivial because we have no extra data. */
|
||||
public UpdateTrustResult(Parcel source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
}
|
||||
|
||||
public static Creator<UpdateTrustResult> CREATOR = new Creator<UpdateTrustResult>() {
|
||||
public UpdateTrustResult createFromParcel(final Parcel source) {
|
||||
return new UpdateTrustResult(source);
|
||||
}
|
||||
|
||||
public UpdateTrustResult[] newArray(final int size) {
|
||||
return new UpdateTrustResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user