bug 642794 - add support to android for removed-files file r=dougt a=blocking-fennec
authorBrad Lassey <blassey@mozilla.com>
Fri, 18 Mar 2011 11:50:19 -0400
changeset 63439 af5988b2e2ca
parent 63438 bb383015d668
child 63440 378591d78e00
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersdougt, blocking-fennec
bugs642794
milestone2.0b13pre
bug 642794 - add support to android for removed-files file r=dougt a=blocking-fennec
embedding/android/GeckoApp.java
toolkit/mozapps/installer/packager.mk
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -433,16 +433,23 @@ abstract public class GeckoApp
         ZipFile zip;
         InputStream listStream;
 
         File componentsDir = new File(sGREDir, "components");
         componentsDir.mkdir();
         zip = new ZipFile(getApplication().getPackageResourcePath());
 
         byte[] buf = new byte[8192];
+        try {
+            if (unpackFile(zip, buf, null, "removed-files"))
+                removeFiles();
+        } catch (Exception ex) {
+            // This file may not be there, so just log any errors and move on
+            Log.w("GeckoApp", "error removing files", ex);
+        }
         unpackFile(zip, buf, null, "application.ini");
         unpackFile(zip, buf, null, getContentProcessName());
         try {
             unpackFile(zip, buf, null, "update.locale");
         } catch (Exception e) {/* this is non-fatal */}
 
         // copy any .xpi file into an extensions/ directory
         Enumeration<? extends ZipEntry> zipEntries = zip.entries();
@@ -450,33 +457,49 @@ abstract public class GeckoApp
           ZipEntry entry = zipEntries.nextElement();
           if (entry.getName().startsWith("extensions/") && entry.getName().endsWith(".xpi")) {
             Log.i("GeckoAppJava", "installing extension : " + entry.getName());
             unpackFile(zip, buf, entry, entry.getName());
           }
         }
     }
 
+    void removeFiles() throws IOException {
+        BufferedReader reader = new BufferedReader(
+            new FileReader(new File(sGREDir, "removed-files")));
+        try {
+            for (String removedFileName = reader.readLine(); 
+                 removedFileName != null; removedFileName = reader.readLine()) {
+                File removedFile = new File(sGREDir, removedFileName);
+                if (removedFile.exists())
+                    removedFile.delete();
+            }
+        } finally {
+            reader.close();
+        }
+        
+    }
+
     boolean haveKilledZombies = false;
 
-    private void unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry,
+    private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry,
                             String name)
         throws IOException, FileNotFoundException
     {
         if (fileEntry == null)
             fileEntry = zip.getEntry(name);
         if (fileEntry == null)
             throw new FileNotFoundException("Can't find " + name + " in " +
                                             zip.getName());
 
         File outFile = new File(sGREDir, name);
         if (outFile.exists() &&
             outFile.lastModified() == fileEntry.getTime() &&
             outFile.length() == fileEntry.getSize())
-            return;
+            return false;
 
         if (!haveKilledZombies) {
             haveKilledZombies = true;
             GeckoAppShell.killAnyZombies();
         }
 
         File dir = outFile.getParentFile();
         if (!outFile.exists())
@@ -490,16 +513,17 @@ abstract public class GeckoApp
         while (fileStream.available() > 0) {
             int read = fileStream.read(buf, 0, buf.length);
             outStream.write(buf, 0, read);
         }
 
         fileStream.close();
         outStream.close();
         outFile.setLastModified(fileEntry.getTime());
+        return true;
     }
 
     public void addEnvToIntent(Intent intent) {
         Map<String,String> envMap = System.getenv();
         Set<Map.Entry<String,String>> envSet = envMap.entrySet();
         Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
         StringBuffer envstr = new StringBuffer();
         int c = 0;
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -174,16 +174,17 @@ DIST_FILES = \
   extensions \
   application.ini \
   platform.ini \
   greprefs.js \
   browserconfig.properties \
   blocklist.xml \
   chrome.manifest \
   update.locale \
+  removed-files \
   $(NULL)
 
 NON_DIST_FILES = \
   classes.dex \
   $(NULL)
 
 UPLOAD_EXTRA_FILES += gecko-unsigned-unaligned.apk