mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 04:45:04 -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;
|
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) {
|
public PgpImportExport(Context context, Progressable progressable) {
|
||||||
super();
|
super();
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
@ -118,10 +114,9 @@ public class PgpImportExport {
|
|||||||
if (aos != null) {
|
if (aos != null) {
|
||||||
aos.close();
|
aos.close();
|
||||||
}
|
}
|
||||||
if (bos != null) {
|
|
||||||
bos.close();
|
bos.close();
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} 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);
|
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(key);
|
||||||
if (result.updated()) {
|
if (!result.success()) {
|
||||||
newKeys += 1;
|
badKeys += 1;
|
||||||
} else {
|
} else if (result.updated()) {
|
||||||
oldKeys += 1;
|
oldKeys += 1;
|
||||||
|
} else {
|
||||||
|
newKeys += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PgpGeneralException e) {
|
} 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
|
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||||
try {
|
int deleted = mContentResolver.delete(
|
||||||
mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||||
|
if (deleted > 0) {
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
||||||
result |= SaveKeyringResult.UPDATED;
|
result |= SaveKeyringResult.UPDATED;
|
||||||
} catch (UnsupportedOperationException e) {
|
} else {
|
||||||
Log.e(Constants.TAG, "Key could not be deleted! Maybe we are creating a new one!", e);
|
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
|
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,14 +577,16 @@ public class ProviderHelper {
|
|||||||
* is already in the database!
|
* is already in the database!
|
||||||
*/
|
*/
|
||||||
public OperationResultParcel saveSecretKeyRing(UncachedKeyRing keyRing) {
|
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();
|
long masterKeyId = keyRing.getMasterKeyId();
|
||||||
log(LogLevel.START, LogType.MSG_IS,
|
log(LogLevel.START, LogType.MSG_IS,
|
||||||
new String[]{PgpKeyHelper.convertKeyIdToHex(masterKeyId)});
|
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
|
// save secret keyring
|
||||||
try {
|
try {
|
||||||
|
@ -44,8 +44,8 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
return mResult;
|
return mResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuccessful() {
|
public boolean success() {
|
||||||
return (mResult & 1) == 1;
|
return (mResult & 1) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationLog getLog() {
|
public OperationLog getLog() {
|
||||||
|
@ -25,13 +25,13 @@ public abstract class OperationResults {
|
|||||||
== (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED);
|
== (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED);
|
||||||
}
|
}
|
||||||
public boolean isOkNew() {
|
public boolean isOkNew() {
|
||||||
return (mResult & RESULT_OK_NEWKEYS) > 0;
|
return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS;
|
||||||
}
|
}
|
||||||
public boolean isOkUpdated() {
|
public boolean isOkUpdated() {
|
||||||
return (mResult & RESULT_OK_UPDATED) > 0;
|
return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED;
|
||||||
}
|
}
|
||||||
public boolean isFailNothing() {
|
public boolean isFailNothing() {
|
||||||
return (mResult & RESULT_FAIL_NOTHING) > 0;
|
return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportResult(Parcel source) {
|
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);
|
R.plurals.import_keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
|
||||||
str += getResources().getQuantityString(
|
str += getResources().getQuantityString(
|
||||||
R.plurals.import_keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
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()) {
|
} else if (result.isOkUpdated()) {
|
||||||
str = getResources().getQuantityString(
|
str = getResources().getQuantityString(
|
||||||
R.plurals.import_keys_updated, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
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 {
|
} else {
|
||||||
duration = 0;
|
duration = 0;
|
||||||
color = Style.RED;
|
color = Style.RED;
|
||||||
|
Loading…
Reference in New Issue
Block a user