Bug 1130784 - FAT32 file create limit code is using a bad error number. r=honzab, a=sledru
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 12 Feb 2015 11:28:50 +0100
changeset 249740 d0d290f35a8419df151f6177101d3c2616928db7
parent 249739 d03da8430432bd0611e2791c0235ed21748c43a0
child 249741 e7fc791997893e1db53e212cb15b295670f30dbf
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab, sledru
bugs1130784
milestone37.0a2
Bug 1130784 - FAT32 file create limit code is using a bad error number. r=honzab, a=sledru
netwerk/cache2/CacheFileIOManager.cpp
netwerk/cache2/CacheIndex.cpp
netwerk/cache2/CacheIndex.h
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -2603,17 +2603,17 @@ CacheFileIOManager::OverLimitEvictionInt
            "for higher level events."));
       mOverLimitEvicting = true;
       return NS_OK;
     }
 
     SHA1Sum::Hash hash;
     uint32_t cnt;
     static uint32_t consecutiveFailures = 0;
-    rv = CacheIndex::GetEntryForEviction(&hash, &cnt);
+    rv = CacheIndex::GetEntryForEviction(false, &hash, &cnt);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = DoomFileByKeyInternal(&hash, true);
     if (NS_SUCCEEDED(rv)) {
       consecutiveFailures = 0;
     } else if (rv == NS_ERROR_NOT_AVAILABLE) {
       LOG(("CacheFileIOManager::OverLimitEvictionInternal() - "
            "DoomFileByKeyInternal() failed. [rv=0x%08x]", rv));
@@ -3591,25 +3591,26 @@ CacheFileIOManager::OpenNSPRHandle(Cache
     // close handle that hasn't been used for the longest time
     rv = ReleaseNSPRHandleInternal(mHandlesByLastUsed[0]);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aCreate) {
     rv = aHandle->mFile->OpenNSPRFileDesc(
            PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0600, &aHandle->mFD);
-    if (rv == NS_ERROR_FILE_NO_DEVICE_SPACE) {
+    if (rv == NS_ERROR_FILE_ALREADY_EXISTS ||  // error from nsLocalFileWin
+        rv == NS_ERROR_FILE_NO_DEVICE_SPACE) { // error from nsLocalFileUnix
       LOG(("CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
            " might reached a limit on FAT32. Will evict a single entry and try "
            "again. [hash=%08x%08x%08x%08x%08x]", LOGSHA1(aHandle->Hash())));
 
       SHA1Sum::Hash hash;
       uint32_t cnt;
 
-      rv = CacheIndex::GetEntryForEviction(&hash, &cnt);
+      rv = CacheIndex::GetEntryForEviction(true, &hash, &cnt);
       if (NS_SUCCEEDED(rv)) {
         rv = DoomFileByKeyInternal(&hash, true);
       }
       if (NS_SUCCEEDED(rv)) {
         rv = aHandle->mFile->OpenNSPRFileDesc(
                PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0600, &aHandle->mFD);
         LOG(("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
              " with hash %08x%08x%08x%08x%08x. %s to create the new file.",
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -1166,17 +1166,17 @@ CacheIndex::HasEntry(const nsACString &a
   }
 
   LOG(("CacheIndex::HasEntry() - result is %u", *_retval));
   return NS_OK;
 }
 
 // static
 nsresult
-CacheIndex::GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt)
+CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash, uint32_t *aCnt)
 {
   LOG(("CacheIndex::GetEntryForEviction()"));
 
   nsRefPtr<CacheIndex> index = gInstance;
 
   if (!index)
     return NS_ERROR_NOT_INITIALIZED;
 
@@ -1199,21 +1199,27 @@ CacheIndex::GetEntryForEviction(SHA1Sum:
   uint32_t i = 0, j = 0;
   uint32_t now = PR_Now() / PR_USEC_PER_SEC;
 
   // find the first expired, non-forced valid entry
   for (i = 0; i < index->mExpirationArray.Length(); i++) {
     if (index->mExpirationArray[i]->mExpirationTime < now) {
       memcpy(&hash, &index->mExpirationArray[i]->mHash, sizeof(SHA1Sum::Hash));
 
-      if (!IsForcedValidEntry(&hash)) {
-        foundEntry = true;
-        break;
+      if (IsForcedValidEntry(&hash)) {
+        continue;
       }
 
+      if (aIgnoreEmptyEntries &&
+          !CacheIndexEntry::GetFileSize(index->mExpirationArray[i])) {
+        continue;
+      }
+
+      foundEntry = true;
+      break;
     } else {
       // all further entries have not expired yet
       break;
     }
   }
 
   if (foundEntry) {
     *aCnt = index->mExpirationArray.Length() - i;
@@ -1228,20 +1234,27 @@ CacheIndex::GetEntryForEviction(SHA1Sum:
     // check if we've already tried all the entries
     if (i == index->mExpirationArray.Length())
       return NS_ERROR_NOT_AVAILABLE;
 
     // find first non-forced valid entry with the lowest frecency
     for (j = 0; j < index->mFrecencyArray.Length(); j++) {
       memcpy(&hash, &index->mFrecencyArray[j]->mHash, sizeof(SHA1Sum::Hash));
 
-      if (!IsForcedValidEntry(&hash)) {
-        foundEntry = true;
-        break;
+      if (IsForcedValidEntry(&hash)) {
+        continue;
       }
+
+      if (aIgnoreEmptyEntries &&
+          !CacheIndexEntry::GetFileSize(index->mFrecencyArray[j])) {
+        continue;
+      }
+
+      foundEntry = true;
+      break;
     }
 
     if (!foundEntry)
       return NS_ERROR_NOT_AVAILABLE;
 
     // forced valid entries skipped in both arrays could overlap, just use max
     *aCnt = index->mFrecencyArray.Length() - std::max(i, j);
 
--- a/netwerk/cache2/CacheIndex.h
+++ b/netwerk/cache2/CacheIndex.h
@@ -636,17 +636,17 @@ public:
   // Returns status of the entry in index for the given key. It can be called
   // on any thread.
   static nsresult HasEntry(const nsACString &aKey, EntryStatus *_retval);
 
   // Returns a hash of the least important entry that should be evicted if the
   // cache size is over limit and also returns a total number of all entries in
   // the index minus the number of forced valid entries that we encounter
   // when searching (see below)
-  static nsresult GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt);
+  static nsresult GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash, uint32_t *aCnt);
 
   // Checks if a cache entry is currently forced valid. Used to prevent an entry
   // (that has been forced valid) from being evicted when the cache size reaches
   // its limit.
   static bool IsForcedValidEntry(const SHA1Sum::Hash *aHash);
 
   // Returns cache size in kB.
   static nsresult GetCacheSize(uint32_t *_retval);