diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-08-19 15:45:42 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-08-19 15:45:59 +0200 |
commit | c725239a69544213229e2d1d0b69b4dca0bcc5d9 (patch) | |
tree | bda7f7e3738070f18e019ecd7a616f5c44006be4 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java | |
parent | 8d668d170c41959897aa78e2f0acc9fac7168d36 (diff) | |
download | open-keychain-c725239a69544213229e2d1d0b69b4dca0bcc5d9.tar.gz open-keychain-c725239a69544213229e2d1d0b69b4dca0bcc5d9.tar.bz2 open-keychain-c725239a69544213229e2d1d0b69b4dca0bcc5d9.zip |
consolidate: split into two steps, can pick up at second step if anything fails
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java index 35833adc6..09275fc95 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java @@ -92,6 +92,10 @@ public class FileImportCache<E extends Parcelable> { } public Iterator<E> readCache() throws IOException { + return readCache(true); + } + + public Iterator<E> readCache(final boolean deleteAfterRead) throws IOException { File cacheDir = mContext.getCacheDir(); if (cacheDir == null) { @@ -166,7 +170,10 @@ public class FileImportCache<E extends Parcelable> { if (!closed) { try { ois.close(); - tempFile.delete(); + if (deleteAfterRead) { + //noinspection ResultOfMethodCallIgnored + tempFile.delete(); + } } catch (IOException e) { // nvm } @@ -177,4 +184,17 @@ public class FileImportCache<E extends Parcelable> { }; } + + public boolean delete() throws IOException { + + File cacheDir = mContext.getCacheDir(); + if (cacheDir == null) { + // https://groups.google.com/forum/#!topic/android-developers/-694j87eXVU + throw new IOException("cache dir is null!"); + } + + final File tempFile = new File(cacheDir, mFilename); + return tempFile.delete(); + } + } |