[Pkg-mozext-commits] [adblock-plus] 81/98: Issue 5279 - Fix broken I/O in non-Firefox applications
David Prévot
taffit at moszumanska.debian.org
Tue Oct 24 01:30:25 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 829dc367c280ebd7d0cf0cb312bcfe3713c19342
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon May 29 13:45:09 2017 +0200
Issue 5279 - Fix broken I/O in non-Firefox applications
---
lib/io.js | 112 +++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 74 insertions(+), 38 deletions(-)
diff --git a/lib/io.js b/lib/io.js
index 6ce3a63..ad11c96 100644
--- a/lib/io.js
+++ b/lib/io.js
@@ -76,6 +76,45 @@ function legacyFile(fileName)
return file;
}
+let fallback = {
+ readFromFile(fileName, listener)
+ {
+ let wrapper = {
+ process(line)
+ {
+ if (line !== null)
+ listener(line);
+ }
+ };
+ return callLegacy("readFromFile", legacyFile(fileName), wrapper);
+ },
+
+ writeToFile(fileName, data)
+ {
+ return callLegacy("writeToFile", legacyFile(fileName), data);
+ },
+
+ copyFile(fromFile, toFile)
+ {
+ return callLegacy("copyFile", legacyFile(fromFile), legacyFile(toFile));
+ },
+
+ renameFile(fromFile, newName)
+ {
+ return callLegacy("renameFile", legacyFile(fromFile), newName);
+ },
+
+ removeFile(fileName)
+ {
+ return callLegacy("removeFile", legacyFile(fileName));
+ },
+
+ statFile(fileName)
+ {
+ return callLegacy("statFile", legacyFile(fileName));
+ }
+};
+
exports.IO =
{
/**
@@ -116,20 +155,6 @@ exports.IO =
processBatch();
});
- }).catch(error =>
- {
- if (error == "NoSuchFile")
- {
- let wrapper = {
- process(line)
- {
- if (line !== null)
- listener(line);
- }
- };
- return callLegacy("readFromFile", legacyFile(fileName), wrapper);
- }
- throw error;
});
},
@@ -159,12 +184,7 @@ exports.IO =
*/
copyFile(fromFile, toFile)
{
- return callWebExt("copyFile", fromFile, toFile).catch(error =>
- {
- if (error == "NoSuchFile")
- return callLegacy("copyFile", legacyFile(fromFile), legacyFile(toFile));
- throw error;
- });
+ return callWebExt("copyFile", fromFile, toFile);
},
/**
@@ -178,12 +198,7 @@ exports.IO =
*/
renameFile(fromFile, newName)
{
- return callWebExt("renameFile", fromFile, newName).catch(error =>
- {
- if (error == "NoSuchFile")
- return callLegacy("renameFile", legacyFile(fromFile), newName);
- throw error;
- });
+ return callWebExt("renameFile", fromFile, newName);
},
/**
@@ -195,12 +210,7 @@ exports.IO =
*/
removeFile(fileName)
{
- return callWebExt("removeFile", fileName).catch(error =>
- {
- if (error == "NoSuchFile")
- return callLegacy("removeFile", legacyFile(fileName));
- throw error;
- });
+ return callWebExt("removeFile", fileName);
},
/**
@@ -222,11 +232,37 @@ exports.IO =
*/
statFile(fileName)
{
- return callWebExt("statFile", fileName).catch(error =>
- {
- if (error == "NoSuchFile")
- return callLegacy("statFile", legacyFile(fileName));
- throw error;
- });
+ return callWebExt("statFile", fileName);
}
};
+
+let {application} = require("info");
+if (application != "firefox" && application != "fennec2")
+{
+ // Currently, only Firefox has a working WebExtensions implementation, other
+ // applications should just use the fallback.
+ exports.IO = fallback;
+}
+else
+{
+ // Add fallbacks to IO methods - fall back to legacy I/O if file wasn't found.
+ for (let name of Object.getOwnPropertyNames(exports.IO))
+ {
+ // No fallback for writeToFile method, new data should always be stored to
+ // new storage only.
+ if (name == "writeToFile")
+ continue;
+
+ let method = exports.IO[name];
+ let fallbackMethod = fallback[name];
+ exports.IO[name] = (...args) =>
+ {
+ return method(...args).catch(error =>
+ {
+ if (error == "NoSuchFile")
+ return fallbackMethod(...args);
+ throw error;
+ });
+ };
+ }
+}
--
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