Bug 396648. nsPermissionManager tries to open two files that usually don't exist. r/sr=biesi, a=bzbarsky
authorsayrer@gmail.com
Thu, 20 Sep 2007 22:09:54 -0700
changeset 6179 aec95d4f55c78bc606872880f90ee2b2abb8aea0
parent 6178 516db4308d5e17f5b10ebeca8877a6621eddb64a
child 6180 80d8fd8d7432b86415821c32a2a0b63cdbfce695
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs396648
milestone1.9a8pre
Bug 396648. nsPermissionManager tries to open two files that usually don't exist. r/sr=biesi, a=bzbarsky
extensions/cookie/nsPermissionManager.cpp
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -631,33 +631,44 @@ static const char kTypeSign = '%';
 static const char kMatchTypeHost[] = "host";
 
 nsresult
 nsPermissionManager::Read()
 {
   nsresult rv;
   
   PRBool readingOldFile = PR_FALSE;
+  nsCOMPtr<nsIInputStream> fileInputStream;
 
-  nsCOMPtr<nsIInputStream> fileInputStream;
-  rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), mPermissionsFile);
-  if (rv == NS_ERROR_FILE_NOT_FOUND) {
+  PRBool fileExists = PR_FALSE;
+  rv = mPermissionsFile->Exists(&fileExists);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (fileExists) {
+    rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream),
+                                    mPermissionsFile);
+  } else {
     // Try finding the old-style file
 
     nsCOMPtr<nsIFile> oldPermissionsFile;
-    rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(oldPermissionsFile));
+    rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
+                                getter_AddRefs(oldPermissionsFile));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = oldPermissionsFile->AppendNative(NS_LITERAL_CSTRING(kOldPermissionsFileName));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), oldPermissionsFile);
-
-    readingOldFile = PR_TRUE;
-
+    rv = oldPermissionsFile->Exists(&fileExists);
+    if (NS_SUCCEEDED(rv) && fileExists) {
+      rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream),
+                                      oldPermissionsFile);
+      readingOldFile = PR_TRUE;
+    } else {
+      rv = NS_ERROR_FILE_NOT_FOUND;
+    }
     /* old format is:
      * host \t number permission \t number permission ... \n
      * if this format isn't respected we move onto the next line in the file.
      * permission is T or F for accept or deny, otherwise a lowercase letter,
      * with a=0, b=1 etc
      */
   }
   // An error path is expected when cookperm.txt is not found either, or when