remove "export to file" code path from export operation

This commit is contained in:
Vincent Breitmoser
2015-09-26 02:20:21 +02:00
parent 15c9fde27f
commit 04fd2eeb79
4 changed files with 6 additions and 74 deletions

View File

@@ -18,11 +18,10 @@
package org.sufficientlysecure.keychain.operations;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Proxy;
@@ -55,7 +54,6 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.FileHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
@@ -82,11 +80,6 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
super(context, providerHelper, progressable, cancelled);
}
public ExportResult uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring,
Proxy proxy) {
return uploadKeyRingToServer(server, keyring.getUncachedKeyRing(), proxy);
}
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
@@ -130,48 +123,6 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
}
}
public ExportResult exportToFile(long[] masterKeyIds, boolean exportSecret, String outputFile) {
OperationLog log = new OperationLog();
if (masterKeyIds != null) {
log.add(LogType.MSG_EXPORT, 0, masterKeyIds.length);
} else {
log.add(LogType.MSG_EXPORT_ALL, 0);
}
// do we have a file name?
if (outputFile == null) {
log.add(LogType.MSG_EXPORT_ERROR_NO_FILE, 1);
return new ExportResult(ExportResult.RESULT_ERROR, log);
}
log.add(LogType.MSG_EXPORT_FILE_NAME, 1, outputFile);
// check if storage is ready
if (!FileHelper.isStorageMounted(outputFile)) {
log.add(LogType.MSG_EXPORT_ERROR_STORAGE, 1);
return new ExportResult(ExportResult.RESULT_ERROR, log);
}
try {
OutputStream outStream = new FileOutputStream(outputFile);
try {
ExportResult result = exportKeyRings(log, masterKeyIds, exportSecret, outStream);
if (result.cancelled()) {
//noinspection ResultOfMethodCallIgnored
new File(outputFile).delete();
}
return result;
} finally {
outStream.close();
}
} catch (IOException e) {
log.add(LogType.MSG_EXPORT_ERROR_FOPEN, 1);
return new ExportResult(ExportResult.RESULT_ERROR, log);
}
}
public ExportResult exportToUri(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
OperationLog log = new OperationLog();
@@ -188,8 +139,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
}
try {
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream
(outputUri);
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream(outputUri);
return exportKeyRings(log, masterKeyIds, exportSecret, outStream);
} catch (FileNotFoundException e) {
log.add(LogType.MSG_EXPORT_ERROR_URI_OPEN, 1);
@@ -359,23 +309,17 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
CanonicalizedPublicKeyRing keyring
= mProviderHelper.getCanonicalizedPublicKeyRing(
exportInput.mCanonicalizedPublicKeyringUri);
return uploadKeyRingToServer(hkpKeyserver, keyring, proxy);
return uploadKeyRingToServer(hkpKeyserver, keyring.getUncachedKeyRing(), proxy);
} else {
return uploadKeyRingToServer(hkpKeyserver, exportInput.mUncachedKeyRing,
proxy);
return uploadKeyRingToServer(hkpKeyserver, exportInput.mUncachedKeyRing, proxy);
}
} catch (ProviderHelper.NotFoundException e) {
Log.e(Constants.TAG, "error uploading key", e);
return new ExportResult(ExportResult.RESULT_ERROR, new OperationLog());
}
}
case EXPORT_FILE: {
return exportToFile(exportInput.mMasterKeyIds, exportInput.mExportSecret,
exportInput.mOutputFile);
}
case EXPORT_URI: {
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret,
exportInput.mOutputUri);
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret, exportInput.mOutputUri);
}
default: { // can never happen, all enum types must be handled above
throw new AssertionError("must not happen, this is a bug!");

View File

@@ -763,16 +763,12 @@ public abstract class OperationResult implements Parcelable {
MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success),
MSG_EXPORT (LogLevel.START, R.plurals.msg_export),
MSG_EXPORT_FILE_NAME (LogLevel.INFO, R.string.msg_export_file_name),
MSG_EXPORT_UPLOAD_PUBLIC (LogLevel.START, R.string.msg_export_upload_public),
MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public),
MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret),
MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all),
MSG_EXPORT_ERROR_NO_FILE (LogLevel.ERROR, R.string.msg_export_error_no_file),
MSG_EXPORT_ERROR_FOPEN (LogLevel.ERROR, R.string.msg_export_error_fopen),
MSG_EXPORT_ERROR_NO_URI (LogLevel.ERROR, R.string.msg_export_error_no_uri),
MSG_EXPORT_ERROR_URI_OPEN (LogLevel.ERROR, R.string.msg_export_error_uri_open),
MSG_EXPORT_ERROR_STORAGE (LogLevel.ERROR, R.string.msg_export_error_storage),
MSG_EXPORT_ERROR_DB (LogLevel.ERROR, R.string.msg_export_error_db),
MSG_EXPORT_ERROR_IO (LogLevel.ERROR, R.string.msg_export_error_io),
MSG_EXPORT_ERROR_KEY (LogLevel.ERROR, R.string.msg_export_error_key),

View File

@@ -38,7 +38,6 @@ public class ExportKeyringParcel implements Parcelable {
public enum ExportType {
UPLOAD_KEYSERVER,
EXPORT_FILE,
EXPORT_URI
}
@@ -54,13 +53,6 @@ public class ExportKeyringParcel implements Parcelable {
mUncachedKeyRing = uncachedKeyRing;
}
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, String outputFile) {
mExportType = ExportType.EXPORT_FILE;
mMasterKeyIds = masterKeyIds;
mExportSecret = exportSecret;
mOutputFile = outputFile;
}
@SuppressWarnings("unused") // TODO: is it used?
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
mExportType = ExportType.EXPORT_URI;

View File

@@ -96,7 +96,7 @@ public class ExportHelper
@Override
public ExportKeyringParcel createOperationInput() {
return new ExportKeyringParcel(mMasterKeyIds, mExportSecret, mExportFile.getAbsolutePath());
return new ExportKeyringParcel(mMasterKeyIds, mExportSecret, Uri.fromFile(mExportFile));
}
@Override