Skip to content

Commit

Permalink
Ensure multiple calls to getExportCacheFilePath() always returns the …
Browse files Browse the repository at this point in the history
…same filename.

The filename returned by getExportCacheFilePath() contains a timestamp,
which can change if called multiple times.

Fixes codinguser#448
  • Loading branch information
rivaldi8 committed Dec 7, 2015
1 parent ef3e8da commit 3a232c0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/java/org/gnucash/android/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 3a232c0

Please sign in to comment.