aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-08-04 11:19:46 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-08-04 11:19:46 +0200
commitb42afcd32cc082d45daf64e37d89ba88f0c3eb56 (patch)
tree295e34f98442b30e24c5170c55a507efa38fec5a /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
parenta8b8ed6f14b917c220d1e46548260e0e9bdf7656 (diff)
downloadopen-keychain-b42afcd32cc082d45daf64e37d89ba88f0c3eb56.tar.gz
open-keychain-b42afcd32cc082d45daf64e37d89ba88f0c3eb56.tar.bz2
open-keychain-b42afcd32cc082d45daf64e37d89ba88f0c3eb56.zip
Fix debug backup/restore methods
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java39
1 files changed, 17 insertions, 22 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
index 7a63ec3d7..ebc53ddf6 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
@@ -316,42 +316,37 @@ public class KeychainDatabase extends SQLiteOpenHelper {
}
private static void copy(File in, File out) throws IOException {
- FileInputStream ss = new FileInputStream(in);
- FileOutputStream ds = new FileOutputStream(out);
+ FileInputStream is = new FileInputStream(in);
+ FileOutputStream os = new FileOutputStream(out);
byte[] buf = new byte[512];
- while (ss.available() > 0) {
- int count = ss.read(buf, 0, 512);
- ds.write(buf, 0, count);
+ while (is.available() > 0) {
+ int count = is.read(buf, 0, 512);
+ os.write(buf, 0, count);
}
}
- public static void debugRead(Context context) throws IOException {
+ public static void debugBackup(Context context, boolean restore) throws IOException {
if (!Constants.DEBUG) {
return;
}
- File in = context.getDatabasePath("debug.db");
- File out = context.getDatabasePath("openkeychain.db");
- if (!in.canRead()) {
- throw new IOException("Cannot read " + in.getName());
- }
- if (!out.canRead()) {
- throw new IOException("Cannot write " + out.getName());
- }
- copy(in, out);
- }
- public static void debugWrite(Context context) throws IOException {
- if (!Constants.DEBUG) {
- return;
+ File in;
+ File out;
+ if (restore) {
+ in = context.getDatabasePath("debug_backup.db");
+ out = context.getDatabasePath("openkeychain.db");
+ } else {
+ in = context.getDatabasePath("openkeychain.db");
+ out = context.getDatabasePath("debug_backup.db");
+ out.createNewFile();
}
- File in = context.getDatabasePath("openkeychain.db");
- File out = context.getDatabasePath("debug.db");
if (!in.canRead()) {
throw new IOException("Cannot read " + in.getName());
}
- if (!out.canRead()) {
+ if (!out.canWrite()) {
throw new IOException("Cannot write " + out.getName());
}
copy(in, out);
}
+
}