diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-06 01:08:12 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-06 01:08:12 +0200 |
commit | 881a50207af0a9f9f5aa69f451110de786779b54 (patch) | |
tree | 776bf4363c3e8736c3678eba93017387fffd8463 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java | |
parent | 0bfac9989f801aa93d8bc336307d60b817995688 (diff) | |
parent | 6ba7536838b8fbc69684bec7c3e847afcb5e9d6a (diff) | |
download | open-keychain-881a50207af0a9f9f5aa69f451110de786779b54.tar.gz open-keychain-881a50207af0a9f9f5aa69f451110de786779b54.tar.bz2 open-keychain-881a50207af0a9f9f5aa69f451110de786779b54.zip |
Merge branch 'master' into yubikey
Conflicts:
.gitmodules
OpenKeychain/build.gradle
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
extern/openpgp-api-lib
settings.gradle
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.java | 43 |
1 files changed, 19 insertions, 24 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..3a859f505 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -165,8 +165,8 @@ public class KeychainDatabase extends SQLiteOpenHelper { // make sure this is only done once, on the first instance! boolean iAmIt = false; - synchronized(KeychainDatabase.class) { - if(!KeychainDatabase.apgHack) { + synchronized (KeychainDatabase.class) { + if (!KeychainDatabase.apgHack) { iAmIt = true; KeychainDatabase.apgHack = true; } @@ -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(DATABASE_NAME); + } else { + in = context.getDatabasePath(DATABASE_NAME); + 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); } + } |