Bug 1428568 - Stop using GetNativePath in libjar. r=mayhemer
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 15 Dec 2017 20:58:51 +0900
changeset 458773 0bb9c745a9dfc887c40118923e3818bfb502d133
parent 458772 a20b068b82f7338db3f565bde5cad4c6f0a7b172
child 458774 a0a032ce94f89b2a738037aa4bd71cf9277948e9
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1428568
milestone60.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 1428568 - Stop using GetNativePath in libjar. r=mayhemer mZips key is used only for internal hashtable lookups, so GetPersistentDescriptor is suitable. MozReview-Commit-ID: 48wDOSjyo3r
modules/libjar/nsJAR.cpp
modules/libjar/nsZipArchive.cpp
modules/libjar/nsZipArchive.h
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -206,21 +206,17 @@ nsJAR::Extract(const nsACString &aEntryN
   }
   else
   {
     PRFileDesc* fd;
     rv = outFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, item->Mode(), &fd);
     if (NS_FAILED(rv)) return rv;
 
     // ExtractFile also closes the fd handle and resolves the symlink if needed
-    nsAutoCString path;
-    rv = outFile->GetNativePath(path);
-    if (NS_FAILED(rv)) return rv;
-
-    rv = mZip->ExtractFile(item, path.get(), fd);
+    rv = mZip->ExtractFile(item, outFile, fd);
   }
   if (NS_FAILED(rv)) return rv;
 
   // nsIFile needs milliseconds, while prtime is in microseconds.
   // non-fatal if this fails, ignore errors
   outFile->SetLastModifiedTime(item->LastModTime() / PR_USEC_PER_MSEC);
 
   return NS_OK;
@@ -296,17 +292,17 @@ nsJAR::GetInputStreamWithSpec(const nsAC
   return rv;
 }
 
 nsresult
 nsJAR::GetJarPath(nsACString& aResult)
 {
   NS_ENSURE_ARG_POINTER(mZipFile);
 
-  return mZipFile->GetNativePath(aResult);
+  return mZipFile->GetPersistentDescriptor(aResult);
 }
 
 nsresult
 nsJAR::GetNSPRFileDesc(PRFileDesc** aNSPRFileDesc)
 {
   if (!aNSPRFileDesc) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
@@ -602,17 +598,17 @@ nsZipReaderCache::~nsZipReaderCache()
 NS_IMETHODIMP
 nsZipReaderCache::IsCached(nsIFile* zipFile, bool* aResult)
 {
   NS_ENSURE_ARG_POINTER(zipFile);
   nsresult rv;
   MutexAutoLock lock(mLock);
 
   nsAutoCString uri;
-  rv = zipFile->GetNativePath(uri);
+  rv = zipFile->GetPersistentDescriptor(uri);
   if (NS_FAILED(rv))
     return rv;
 
   uri.InsertLiteral("file:", 0);
 
   *aResult = mZips.Contains(uri);
   return NS_OK;
 }
@@ -625,17 +621,17 @@ nsZipReaderCache::GetZip(nsIFile* zipFil
   nsresult rv;
   MutexAutoLock lock(mLock);
 
 #ifdef ZIP_CACHE_HIT_RATE
   mZipCacheLookups++;
 #endif
 
   nsAutoCString uri;
-  rv = zipFile->GetNativePath(uri);
+  rv = zipFile->GetPersistentDescriptor(uri);
   if (NS_FAILED(rv)) return rv;
 
   uri.InsertLiteral("file:", 0);
 
   RefPtr<nsJAR> zip;
   mZips.Get(uri, getter_AddRefs(zip));
   if (zip) {
 #ifdef ZIP_CACHE_HIT_RATE
@@ -685,17 +681,17 @@ nsZipReaderCache::GetInnerZip(nsIFile* z
 
   MutexAutoLock lock(mLock);
 
 #ifdef ZIP_CACHE_HIT_RATE
   mZipCacheLookups++;
 #endif
 
   nsAutoCString uri;
-  rv = zipFile->GetNativePath(uri);
+  rv = zipFile->GetPersistentDescriptor(uri);
   if (NS_FAILED(rv)) return rv;
 
   uri.InsertLiteral("jar:", 0);
   uri.AppendLiteral("!/");
   uri.Append(entry);
 
   RefPtr<nsJAR> zip;
   mZips.Get(uri, getter_AddRefs(zip));
@@ -728,17 +724,17 @@ nsZipReaderCache::GetFd(nsIFile* zipFile
   return NS_ERROR_NOT_IMPLEMENTED;
 #else
   if (!zipFile) {
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv;
   nsAutoCString uri;
-  rv = zipFile->GetNativePath(uri);
+  rv = zipFile->GetPersistentDescriptor(uri);
   if (NS_FAILED(rv)) {
     return rv;
   }
   uri.InsertLiteral("file:", 0);
 
   MutexAutoLock lock(mLock);
   RefPtr<nsJAR> zip;
   mZips.Get(uri, getter_AddRefs(zip));
@@ -876,17 +872,17 @@ nsZipReaderCache::Observe(nsISupports *a
       nsDependentString fileName(aSomeData);
       Unused << NS_NewLocalFile(fileName, false, getter_AddRefs(file));
     }
 
     if (!file)
       return NS_OK;
 
     nsAutoCString uri;
-    if (NS_FAILED(file->GetNativePath(uri)))
+    if (NS_FAILED(file->GetPersistentDescriptor(uri)))
       return NS_OK;
 
     uri.InsertLiteral("file:", 0);
 
     MutexAutoLock lock(mLock);
 
     RefPtr<nsJAR> zip;
     mZips.Get(uri, getter_AddRefs(zip));
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -468,17 +468,17 @@ MOZ_WIN_MEM_TRY_CATCH(return nullptr)
 }
 
 //---------------------------------------------
 // nsZipArchive::ExtractFile
 // This extracts the item to the filehandle provided.
 // If 'aFd' is null, it only tests the extraction.
 // On extraction error(s) it removes the file.
 //---------------------------------------------
-nsresult nsZipArchive::ExtractFile(nsZipItem *item, const char *outname,
+nsresult nsZipArchive::ExtractFile(nsZipItem *item, nsIFile* outFile,
                                    PRFileDesc* aFd)
 {
   if (!item)
     return NS_ERROR_ILLEGAL_VALUE;
   if (!mFd)
     return NS_ERROR_FAILURE;
 
   // Directory extraction is handled in nsJAR::Extract,
@@ -507,18 +507,19 @@ nsresult nsZipArchive::ExtractFile(nsZip
       rv = NS_ERROR_FILE_DISK_FULL;
       break;
     }
   }
 
   //-- delete the file on errors
   if (aFd) {
     PR_Close(aFd);
-    if (rv != NS_OK)
-      PR_Delete(outname);
+    if (NS_FAILED(rv) && outFile) {
+      outFile->Remove(false);
+    }
   }
 
   return rv;
 }
 
 //---------------------------------------------
 // nsZipArchive::FindInit
 //---------------------------------------------
--- a/modules/libjar/nsZipArchive.h
+++ b/modules/libjar/nsZipArchive.h
@@ -155,17 +155,17 @@ public:
   /**
    * ExtractFile
    *
    * @param   zipEntry   Name of file in archive to extract
    * @param   outFD      Filedescriptor to write contents to
    * @param   outname    Name of file to write to
    * @return  status code
    */
-  nsresult ExtractFile(nsZipItem * zipEntry, const char *outname, PRFileDesc * outFD);
+  nsresult ExtractFile(nsZipItem * zipEntry, nsIFile* outFile, PRFileDesc * outFD);
 
   /**
    * FindInit
    *
    * Initializes a search for files in the archive. FindNext() returns
    * the actual matches. The nsZipFind must be deleted when you're done
    *
    * @param   aPattern    a string or RegExp pattern to search for