mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 03:25:05 -05:00
import-log: properly distinguish return states
This commit is contained in:
parent
47368f1d24
commit
dea98a4a7e
@ -58,10 +58,6 @@ public class PgpImportExport {
|
||||
|
||||
private ProviderHelper mProviderHelper;
|
||||
|
||||
public static final int RETURN_OK = 0;
|
||||
public static final int RETURN_BAD = -2;
|
||||
public static final int RETURN_UPDATED = 1;
|
||||
|
||||
public PgpImportExport(Context context, Progressable progressable) {
|
||||
super();
|
||||
this.mContext = context;
|
||||
@ -118,10 +114,9 @@ public class PgpImportExport {
|
||||
if (aos != null) {
|
||||
aos.close();
|
||||
}
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
// this is just a finally thing, no matter if it doesn't work out.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,10 +148,12 @@ public class PgpImportExport {
|
||||
}
|
||||
|
||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(key);
|
||||
if (result.updated()) {
|
||||
newKeys += 1;
|
||||
} else {
|
||||
if (!result.success()) {
|
||||
badKeys += 1;
|
||||
} else if (result.updated()) {
|
||||
oldKeys += 1;
|
||||
} else {
|
||||
newKeys += 1;
|
||||
}
|
||||
|
||||
} catch (PgpGeneralException e) {
|
||||
|
@ -297,12 +297,12 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
try {
|
||||
mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||
int deleted = mContentResolver.delete(
|
||||
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||
if (deleted > 0) {
|
||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
||||
result |= SaveKeyringResult.UPDATED;
|
||||
} catch (UnsupportedOperationException e) {
|
||||
Log.e(Constants.TAG, "Key could not be deleted! Maybe we are creating a new one!", e);
|
||||
} else {
|
||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
|
||||
}
|
||||
|
||||
@ -577,14 +577,16 @@ public class ProviderHelper {
|
||||
* is already in the database!
|
||||
*/
|
||||
public OperationResultParcel saveSecretKeyRing(UncachedKeyRing keyRing) {
|
||||
if (!keyRing.isSecret()) {
|
||||
log(LogLevel.ERROR, LogType.MSG_IS_BAD_TYPE_PUBLIC);
|
||||
return new OperationResultParcel(1, mLog);
|
||||
}
|
||||
|
||||
long masterKeyId = keyRing.getMasterKeyId();
|
||||
log(LogLevel.START, LogType.MSG_IS,
|
||||
new String[]{PgpKeyHelper.convertKeyIdToHex(masterKeyId)});
|
||||
mIndent += 1;
|
||||
|
||||
if (!keyRing.isSecret()) {
|
||||
log(LogLevel.ERROR, LogType.MSG_IS_BAD_TYPE_PUBLIC);
|
||||
return new OperationResultParcel(1, mLog);
|
||||
}
|
||||
|
||||
// save secret keyring
|
||||
try {
|
||||
|
@ -44,8 +44,8 @@ public class OperationResultParcel implements Parcelable {
|
||||
return mResult;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return (mResult & 1) == 1;
|
||||
public boolean success() {
|
||||
return (mResult & 1) == 0;
|
||||
}
|
||||
|
||||
public OperationLog getLog() {
|
||||
|
@ -25,13 +25,13 @@ public abstract class OperationResults {
|
||||
== (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED);
|
||||
}
|
||||
public boolean isOkNew() {
|
||||
return (mResult & RESULT_OK_NEWKEYS) > 0;
|
||||
return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS;
|
||||
}
|
||||
public boolean isOkUpdated() {
|
||||
return (mResult & RESULT_OK_UPDATED) > 0;
|
||||
return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED;
|
||||
}
|
||||
public boolean isFailNothing() {
|
||||
return (mResult & RESULT_FAIL_NOTHING) > 0;
|
||||
return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
|
||||
}
|
||||
|
||||
public ImportResult(Parcel source) {
|
||||
|
@ -404,12 +404,12 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
R.plurals.import_keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
|
||||
str += getResources().getQuantityString(
|
||||
R.plurals.import_keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
||||
} else if (result.isOkNew()) {
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.import_keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
|
||||
} else if (result.isOkUpdated()) {
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.import_keys_updated, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
||||
} else if (result.isOkNew()) {
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.import_keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
|
Loading…
Reference in New Issue
Block a user