From 3a232c0151a89a9f18b0383e545830fb7533abd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Magaz=20Gra=C3=A7a?= Date: Sun, 6 Dec 2015 17:59:06 +0100 Subject: [PATCH] Ensure multiple calls to getExportCacheFilePath() always returns the same filename. The filename returned by getExportCacheFilePath() contains a timestamp, which can change if called multiple times. Fixes https://github.com/codinguser/gnucash-android/issues/448 --- .../org/gnucash/android/export/Exporter.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/export/Exporter.java b/app/src/main/java/org/gnucash/android/export/Exporter.java index 7e2878a8d..e9941cb5c 100644 --- a/app/src/main/java/org/gnucash/android/export/Exporter.java +++ b/app/src/main/java/org/gnucash/android/export/Exporter.java @@ -103,6 +103,7 @@ public abstract class Exporter { protected PricesDbAdapter mPricesDbAdapter; protected CommoditiesDbAdapter mCommoditiesDbAdapter; protected Context mContext; + private String mExportCacheFilePath; public Exporter(ExportParams params, SQLiteDatabase db) { this.mExportParams = params; @@ -123,6 +124,7 @@ public Exporter(ExportParams params, SQLiteDatabase db) { mCommoditiesDbAdapter = new CommoditiesDbAdapter(db); } + mExportCacheFilePath = null; mCacheDir = new File(mContext.getCacheDir(), params.getExportFormat().name()); mCacheDir.mkdir(); purgeDirectory(mCacheDir); @@ -184,10 +186,16 @@ private void purgeDirectory(File directory){ * @return Absolute path to file */ protected String getExportCacheFilePath(){ - String cachePath = mCacheDir.getAbsolutePath(); - if (!cachePath.endsWith("/")) - cachePath += "/"; - return cachePath + buildExportFilename(mExportParams.getExportFormat()); + // The file name contains a timestamp, so ensure it doesn't change with multiple calls to + // avoid issues like #448 + if (mExportCacheFilePath == null) { + String cachePath = mCacheDir.getAbsolutePath(); + if (!cachePath.endsWith("/")) + cachePath += "/"; + mExportCacheFilePath = cachePath + buildExportFilename(mExportParams.getExportFormat()); + } + + return mExportCacheFilePath; } /**