Skip to content

Commit 40ed199

Browse files
authored
Fixed app cache dir changes issue (parse-community#1158)
ParsePlugins :: - `getCacheDir()`, `getFilesDir()` APIs now has support for backward compatibility before migration to v3.0.0
1 parent 3cd4581 commit 40ed199

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

parse/src/main/java/com/parse/ParsePlugins.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,17 @@ InstallationId installationId() {
178178
File getCacheDir() {
179179
synchronized (lock) {
180180
if (cacheDir == null) {
181-
cacheDir = new File(applicationContext.getCacheDir(), "com.parse");
181+
/*
182+
Check for old reference file before migration to v3.0.0.
183+
If old reference found, copy the ref to new directory and delete the ref.
184+
*/
185+
File oldRef = applicationContext.getDir("Parse", Context.MODE_PRIVATE);
186+
if (oldRef.exists()) {
187+
cacheDir = new File(oldRef, "com.parse");
188+
oldRef.deleteOnExit();
189+
} else {
190+
cacheDir = new File(applicationContext.getCacheDir(), "com.parse");
191+
}
182192
}
183193
return createFileDir(cacheDir);
184194
}
@@ -187,7 +197,17 @@ File getCacheDir() {
187197
File getFilesDir() {
188198
synchronized (lock) {
189199
if (filesDir == null) {
190-
filesDir = new File(applicationContext.getFilesDir(), "com.parse");
200+
/*
201+
Check for old reference file before migration to v3.0.0.
202+
If old reference found, copy the ref to new directory and delete the ref.
203+
*/
204+
File oldRef = applicationContext.getDir("Parse", Context.MODE_PRIVATE);
205+
if (oldRef.exists()) {
206+
filesDir = new File(oldRef, "com.parse");
207+
oldRef.deleteOnExit();
208+
} else {
209+
filesDir = new File(applicationContext.getFilesDir(), "com.parse");
210+
}
191211
}
192212
return createFileDir(filesDir);
193213
}

0 commit comments

Comments
 (0)