Commit ca520fa8 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 727960 - When extracting libraries, reuse cached library if it is newer than the apk. r=tglek

parent a3d8439a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ ElfLoader::Load(const char *path, int flags, LibHandle *parent)
       * environment variable. */
      const char *extract = getenv("MOZ_LINKER_EXTRACT");
      if (extract && !strncmp(extract, "1", 2 /* Including '\0' */))
        mappable = MappableExtractFile::Create(name, &s);
        mappable = MappableExtractFile::Create(name, zip, &s);
      if (!mappable) {
        if (s.GetType() == Zip::Stream::DEFLATE) {
          mappable = MappableDeflate::Create(name, zip, &s);
+17 −6
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#ifdef ANDROID
#include <linux/ashmem.h>
#endif
#include <sys/stat.h>
#include "ElfLoader.h"
#include "SeekableZStream.h"
#include "Logging.h"
@@ -24,7 +25,8 @@
#define PAGE_MASK (~ (PAGE_SIZE - 1))
#endif

MappableFile *MappableFile::Create(const char *path)
Mappable *
MappableFile::Create(const char *path)
{
  int fd = open(path, O_RDONLY);
  if (fd != -1)
@@ -62,8 +64,8 @@ MappableFile::finalize()
  fd = -1;
}

MappableExtractFile *
MappableExtractFile::Create(const char *name, Zip::Stream *stream)
Mappable *
MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
{
  const char *cachePath = getenv("MOZ_LINKER_CACHE");
  if (!cachePath || !*cachePath) {
@@ -73,7 +75,16 @@ MappableExtractFile::Create(const char *name, Zip::Stream *stream)
  }
  AutoDeleteArray<char> path = new char[strlen(cachePath) + strlen(name) + 2];
  sprintf(path, "%s/%s", cachePath, name);
  debug("Extracting to %s", (char *)path);
  struct stat cacheStat;
  if (stat(path, &cacheStat) == 0) {
    struct stat zipStat;
    stat(zip->GetName(), &zipStat);
    if (cacheStat.st_mtime > zipStat.st_mtime) {
      debug("Reusing %s", static_cast<char *>(path));
      return MappableFile::Create(path);
    }
  }
  debug("Extracting to %s", static_cast<char *>(path));
  AutoCloseFD fd = open(path, O_TRUNC | O_RDWR | O_CREAT | O_NOATIME,
                              S_IRUSR | S_IWUSR);
  if (fd == -1) {
@@ -246,7 +257,7 @@ private:
};


MappableDeflate *
Mappable *
MappableDeflate::Create(const char *name, Zip *zip, Zip::Stream *stream)
{
  MOZ_ASSERT(stream->GetType() == Zip::Stream::DEFLATE);
@@ -324,7 +335,7 @@ MappableDeflate::finalize()
  zip = NULL;
}

MappableSeekableZStream *
Mappable *
MappableSeekableZStream::Create(const char *name, Zip *zip,
                                Zip::Stream *stream)
{
+4 −10
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public:
  /**
   * Create a MappableFile instance for the given file path.
   */
  static MappableFile *Create(const char *path);
  static Mappable *Create(const char *path);

  /* Inherited from Mappable */
  virtual void *mmap(const void *addr, size_t length, int prot, int flags, off_t offset);
@@ -99,14 +99,8 @@ public:
   * Create a MappableExtractFile instance for the given Zip stream. The name
   * argument is used to create the cache file in the cache directory.
   */
  static MappableExtractFile *Create(const char *name, Zip::Stream *stream);
  static Mappable *Create(const char *name, Zip *zip, Zip::Stream *stream);

  /**
   * Returns the path of the extracted file.
   */
  char *GetPath() {
    return path;
  }
private:
  MappableExtractFile(int fd, char *path)
  : MappableFile(fd), path(path), pid(getpid()) { }
@@ -148,7 +142,7 @@ public:
   * argument is used for an appropriately named temporary file, and the Zip
   * instance is given for the MappableDeflate to keep a reference of it.
   */
  static MappableDeflate *Create(const char *name, Zip *zip, Zip::Stream *stream);
  static Mappable *Create(const char *name, Zip *zip, Zip::Stream *stream);

  /* Inherited from Mappable */
  virtual void *mmap(const void *addr, size_t length, int prot, int flags, off_t offset);
@@ -182,7 +176,7 @@ public:
   * Zip instance is given for the MappableSeekableZStream to keep a reference
   * of it.
   */
  static MappableSeekableZStream *Create(const char *name, Zip *zip,
  static Mappable *Create(const char *name, Zip *zip,
                                         Zip::Stream *stream);

  /* Inherited from Mappable */