Bug 1233434 - Fixing download failure on a multi-user GNU/Linux machine. r=bagder a=lizzard
authorAidin Gharibnavaz <aidin@aidinhut.com>
Sat, 19 Dec 2015 22:11:00 +0330
changeset 298644 fa63deeed20e63316da128f50672855709fed25c
parent 298641 d83046b974f3470301ee762814b52099033751e4
child 298645 146f494b6a79f452193a2a35b7c5a547d18ffbbe
child 298647 2db6f8260cfb135f4e8a504fb3dec525c6857308
push id994
push userkwierso@gmail.com
push dateWed, 06 Jan 2016 00:07:49 +0000
treeherdermozilla-release@fa63deeed20e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder, lizzard
bugs1233434
milestone43.0.4
Bug 1233434 - Fixing download failure on a multi-user GNU/Linux machine. r=bagder a=lizzard
uriloader/exthandler/nsExternalHelperAppService.cpp
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -411,22 +411,22 @@ static nsresult GetDownloadDirectory(nsI
   PRUint32 permissions;
   rv = dir->GetPermissions(&permissions);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (permissions != PR_IRWXU) {
     const char* userName = PR_GetEnv("USERNAME");
     if (!userName || !*userName) {
       userName = PR_GetEnv("USER");
-      if (!userName || !*userName) {
-        userName = PR_GetEnv("LOGNAME");
-      }
-      else {
-        userName = "mozillaUser";
-      }
+    }
+    if (!userName || !*userName) {
+      userName = PR_GetEnv("LOGNAME");
+    }
+    if (!userName || !*userName) {
+      userName = "mozillaUser";
     }
 
     nsAutoString userDir;
     userDir.AssignLiteral("mozilla_");
     userDir.AppendASCII(userName);
     userDir.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
 
     int counter = 0;
@@ -442,17 +442,22 @@ static nsresult GetDownloadDirectory(nsI
       rv = finalPath->Exists(&pathExists);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (pathExists) {
         // If this path has the right permissions, use it.
         rv = finalPath->GetPermissions(&permissions);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        if (permissions == PR_IRWXU) {
+        // Ensuring the path is writable by the current user.
+        bool isWritable;
+        rv = finalPath->IsWritable(&isWritable);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        if (permissions == PR_IRWXU && isWritable) {
           dir = finalPath;
           break;
         }
       }
 
       rv = finalPath->Create(nsIFile::DIRECTORY_TYPE, PR_IRWXU);
       if (NS_SUCCEEDED(rv)) {
         dir = finalPath;