]> khamidou — GitHub mirrors - electron.git/commitdiff
Clean cached asar archives when quitting.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 13:49:01 +0000 (21:49 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 13:49:01 +0000 (21:49 +0800)
atom/common/api/atom_api_asar.cc
atom/common/lib/asar.coffee

index efce7f3e17eb5acf479864c7d84932e26244ee5f..6d7ff76351dc2d4b26f58caf448bc96ef55b7c1d 100644 (file)
@@ -75,6 +75,11 @@ class Archive : public mate::Wrappable {
     return mate::ConvertToV8(isolate, new_path);
   }
 
+  // Free the resources used by archive.
+  void Destroy() {
+    archive_.reset();
+  }
+
   // mate::Wrappable:
   mate::ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) {
     return mate::ObjectTemplateBuilder(isolate)
@@ -82,7 +87,8 @@ class Archive : public mate::Wrappable {
         .SetMethod("getFileInfo", &Archive::GetFileInfo)
         .SetMethod("stat", &Archive::Stat)
         .SetMethod("readdir", &Archive::Readdir)
-        .SetMethod("copyFileOut", &Archive::CopyFileOut);
+        .SetMethod("copyFileOut", &Archive::CopyFileOut)
+        .SetMethod("destroy", &Archive::Destroy);
   }
 
  private:
index ef186fe120ce4620bb8a9aab927bd696c0ec0a62..f3f9fc6a85507ca786dc05912340bdafe0672dc4 100644 (file)
@@ -6,12 +6,19 @@ util = require 'util'
 # Cache asar archive objects.
 cachedArchives = {}
 getOrCreateArchive = (p) ->
-  unless cachedArchives[p]?
-    cachedArchives[p] = asar.createArchive p
-  cachedArchives[p]
+  archive = cachedArchives[p]
+  return archive if archive?
+  archive = asar.createArchive p
+  return false unless archive
+  cachedArchives[p] = archive
+
+# Clean cache on quit.
+process.on 'exit', ->
+  archive.destroy() for p, archive of cachedArchives
 
 # Separate asar package's path from full path.
 splitPath = (p) ->
+  return [false, p] unless typeof p is 'string'
   components = p.split path.sep
   for c, i in components by -1
     if path.extname(c) is '.asar'