OSDN Git Service

Mark FileCache initialized after init really goes through.
authorHung-ying Tyan <tyanh@google.com>
Wed, 9 May 2012 02:38:11 +0000 (10:38 +0800)
committerHung-ying Tyan <tyanh@google.com>
Wed, 9 May 2012 02:46:51 +0000 (10:46 +0800)
Bug: 5988196
Change-Id: Ia826ce6a33c200a2cd09c21d7ef22f4dd161caa9

gallerycommon/src/com/android/gallery3d/common/FileCache.java

index 938ef8c..a69487f 100644 (file)
@@ -191,7 +191,6 @@ public class FileCache implements Closeable {
 
     private synchronized void initialize() {
         if (mInitialized) return;
-        mInitialized = true;
 
         if (!mRootDir.isDirectory()) {
             mRootDir.mkdirs();
@@ -209,6 +208,10 @@ public class FileCache implements Closeable {
             cursor.close();
         }
         if (mTotalBytes > mCapacity) freeSomeSpaceIfNeed(MAX_DELETE_COUNT);
+
+        // Mark initialized when everything above went through. If an exception was thrown,
+        // initialize() will be retried later.
+        mInitialized = true;
     }
 
     private void freeSomeSpaceIfNeed(int maxDeleteFileCount) {