Bug 1364984 - use non-deprecated API for finding the temporary directory on OS X; r=mstange
authorColin Dean <colin.dean@specialiapps.org>
Wed, 07 Jun 2017 20:40:50 -0400
changeset 362927 8a3691625489b1f21fca5aa93cb8eee626068a19
parent 362926 c5aaa3f7b79e2c8ccec4447b9c38109677d4cd01
child 362928 76dd2108b4ae49d518e70a97e5070894685af41f
push id31989
push usercbook@mozilla.com
push dateThu, 08 Jun 2017 12:44:27 +0000
treeherdermozilla-central@6491fb29e7fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1364984
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1364984 - use non-deprecated API for finding the temporary directory on OS X; r=mstange FSFindFolder is deprecated as of 10.9 and apparently continues to work...except for the case of finding the temporary directory when the user's home directory lives on an NFS mount (!). Using NSTemporaryDirectory does The Right Thing here, so let's use that instead.
xpcom/io/CocoaFileUtils.h
xpcom/io/CocoaFileUtils.mm
xpcom/io/SpecialSystemDirectory.cpp
--- a/xpcom/io/CocoaFileUtils.h
+++ b/xpcom/io/CocoaFileUtils.h
@@ -23,12 +23,13 @@ nsresult GetFileTypeCode(CFURLRef aUrl, 
 nsresult SetFileTypeCode(CFURLRef aUrl, OSType aTypeCode);
 void     AddOriginMetadataToFile(const CFStringRef filePath,
                                  const CFURLRef sourceURL,
                                  const CFURLRef referrerURL);
 void     AddQuarantineMetadataToFile(const CFStringRef filePath,
                                      const CFURLRef sourceURL,
                                      const CFURLRef referrerURL,
                                      const bool isFromWeb);
+CFURLRef GetTemporaryFolderCFURLRef();
 
 } // namespace CocoaFileUtils
 
 #endif
--- a/xpcom/io/CocoaFileUtils.mm
+++ b/xpcom/io/CocoaFileUtils.mm
@@ -252,9 +252,16 @@ void AddQuarantineMetadataToFile(const C
                                    quarantinePropKey,
                                    mutQuarantineProps,
                                    NULL);
 
   ::CFRelease(fileURL);
   ::CFRelease(mutQuarantineProps);
 }
 
+CFURLRef GetTemporaryFolderCFURLRef()
+{
+  NSString* tempDir = ::NSTemporaryDirectory();
+  return tempDir == nil ? NULL : (CFURLRef)[NSURL fileURLWithPath:tempDir
+                                                      isDirectory:YES];
+}
+
 } // namespace CocoaFileUtils
--- a/xpcom/io/SpecialSystemDirectory.cpp
+++ b/xpcom/io/SpecialSystemDirectory.cpp
@@ -22,16 +22,19 @@
 
 #elif defined(XP_UNIX)
 
 #include <limits.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/param.h>
 #include "prenv.h"
+#if defined(MOZ_WIDGET_COCOA)
+#include "CocoaFileUtils.h"
+#endif
 
 #endif
 
 #ifndef MAXPATHLEN
 #ifdef PATH_MAX
 #define MAXPATHLEN PATH_MAX
 #elif defined(MAX_PATH)
 #define MAXPATHLEN MAX_PATH
@@ -761,20 +764,30 @@ GetSpecialSystemDirectory(SystemDirector
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 #if defined (MOZ_WIDGET_COCOA)
 nsresult
 GetOSXFolderType(short aDomain, OSType aFolderType, nsIFile** aLocalFile)
 {
+  nsresult rv = NS_ERROR_FAILURE;
+
+  if (aFolderType == kTemporaryFolderType) {
+    NS_NewLocalFile(EmptyString(), true, aLocalFile);
+    nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*aLocalFile));
+    if (localMacFile) {
+      rv = localMacFile->InitWithCFURL(
+             CocoaFileUtils::GetTemporaryFolderCFURLRef());
+    }
+    return rv;
+  }
+
   OSErr err;
   FSRef fsRef;
-  nsresult rv = NS_ERROR_FAILURE;
-
   err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
   if (err == noErr) {
     NS_NewLocalFile(EmptyString(), true, aLocalFile);
     nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*aLocalFile));
     if (localMacFile) {
       rv = localMacFile->InitWithFSRef(&fsRef);
     }
   }