[Pkg-mozext-commits] [adblock-plus] 73/98: Issue 5051 - Make sure that custom backups don't rely on FilterStorage's I/O

David Prévot taffit at moszumanska.debian.org
Tue Oct 24 01:30:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit a7023ffe3a7fff7c0bb643fa892406045cdacdf7
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Thu Mar 30 18:40:51 2017 +0200

    Issue 5051 - Make sure that custom backups don't rely on FilterStorage's I/O
---
 chrome/content/ui/filters-backup.js | 62 +++++++++++++++++++++----------------
 dependencies                        |  2 +-
 2 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/chrome/content/ui/filters-backup.js b/chrome/content/ui/filters-backup.js
index f0f5ac5..b3f8b94 100644
--- a/chrome/content/ui/filters-backup.js
+++ b/chrome/content/ui/filters-backup.js
@@ -108,7 +108,7 @@ var Backup =
         item.setAttribute("label", label);
         item.addEventListener("command", function()
         {
-          Backup.restoreAllData(backup.file);
+          FilterStorage.restoreBackup(backup.index);
         }, false);
         this.restoreInsertionPoint.parentNode.insertBefore(item, this.restoreInsertionPoint.nextSibling);
       }
@@ -141,34 +141,40 @@ var Backup =
    */
   restoreAllData: function(/**nsIFile*/ file)
   {
-    let stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
-    stream.init(file, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
-    stream.QueryInterface(Ci.nsILineInputStream);
-
+    let sink = FilterStorage.importData();
     let lines = [];
-    let line = {value: null};
-    if (stream.readLine(line))
-      lines.push(line.value);
-    if (stream.readLine(line))
-      lines.push(line.value);
-    stream.close();
-
-    let match;
-    if (lines.length < 2 || lines[0] != "# Adblock Plus preferences" || !(match = /version=(\d+)/.exec(lines[1])))
-    {
-      Utils.alert(window, E("backupButton").getAttribute("_restoreError"), E("backupButton").getAttribute("_restoreDialogTitle"));
-      return;
-    }
+    IO.readFromFile(file, {
+      process(line)
+      {
+        if (line === null)
+        {
+          let match;
+          if (lines.length < 2 || lines[0] != "# Adblock Plus preferences" || !(match = /version=(\d+)/.exec(lines[1])))
+          {
+            Utils.alert(window, E("backupButton").getAttribute("_restoreError"), E("backupButton").getAttribute("_restoreDialogTitle"));
+            return;
+          }
 
-    let warning = E("backupButton").getAttribute("_restoreCompleteWarning");
-    let minVersion = parseInt(match[1], 10);
-    if (minVersion > FilterStorage.formatVersion)
-      warning += "\n\n" + E("backupButton").getAttribute("_restoreVersionWarning");
+          let warning = E("backupButton").getAttribute("_restoreCompleteWarning");
+          let minVersion = parseInt(match[1], 10);
+          if (minVersion > FilterStorage.formatVersion)
+            warning += "\n\n" + E("backupButton").getAttribute("_restoreVersionWarning");
 
-    if (!Utils.confirm(window, warning, E("backupButton").getAttribute("_restoreDialogTitle")))
-      return;
+          if (!Utils.confirm(window, warning, E("backupButton").getAttribute("_restoreDialogTitle")))
+            return;
+        }
+        else if (lines.length < 2)
+          lines.push(line);
 
-    FilterStorage.loadFromDisk(file);
+        sink(line);
+      }
+    }, error =>
+    {
+      if (error)
+        alert(error);
+      else
+        FilterStorage.saveToDisk();
+    });
   },
 
   /**
@@ -284,7 +290,11 @@ var Backup =
    */
   backupAllData: function(/**nsIFile*/ file)
   {
-    FilterStorage.saveToDisk(file);
+    IO.writeToFile(file, FilterStorage.exportData(), error =>
+    {
+      if (error)
+        alert(error);
+    });
   },
 
   /**
diff --git a/dependencies b/dependencies
index 1e44311..31fd59f 100644
--- a/dependencies
+++ b/dependencies
@@ -1,5 +1,5 @@
 _root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
 _self = buildtools/ensure_dependencies.py
 buildtools = buildtools hg:daa9df1ee39f git:3ab934a
-adblockpluscore = adblockpluscore hg:3bdddf0e8343 git:bb21628
+adblockpluscore = adblockpluscore hg:c8d4a462860a git:7376c58
 adblockplusui = adblockplusui hg:8ceaabb9c639 git:6222fd2

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list