From b88231533ac82256f8c04c137496bec2f1c40241 Mon Sep 17 00:00:00 2001 From: wangmengyan95 Date: Wed, 9 Sep 2015 18:58:11 -0700 Subject: [PATCH] Manually delete cacheFile before we write to it --- Parse/src/main/java/com/parse/ParseFileController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Parse/src/main/java/com/parse/ParseFileController.java b/Parse/src/main/java/com/parse/ParseFileController.java index 4a7b05151..f5c3ea211 100644 --- a/Parse/src/main/java/com/parse/ParseFileController.java +++ b/Parse/src/main/java/com/parse/ParseFileController.java @@ -224,6 +224,10 @@ public Task then(Task task) throws Exception { return task.cast(); } + // Since we give the cacheFile pointer to developers, it is not safe to guarantee + // cacheFile always does not exist here, so it is better to delete it manually, + // otherwise moveFile may throw an exception. + ParseFileUtils.deleteQuietly(cacheFile); ParseFileUtils.moveFile(tempFile, cacheFile); return Task.forResult(cacheFile); }