www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 52d38c9dafa5d3717e9b56d5519c32b5fff68563
parent 7f9b29f751ac37bfb752116b84c2ff48b7cbfc1b
Author: Simon Kornblith <simon@simonster.com>
Date:   Sun, 20 Mar 2011 08:26:25 +0000

prevent integration pipe from blocking and make sure integration pipe gets removed


Diffstat:
Mchrome/content/zotero/xpcom/integration.js | 34+++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js @@ -186,29 +186,40 @@ Zotero.Integration = new function() { * Reads from the temp file set up to handle integration pipe and executes the appropriate * integration command */ - var _integrationPipeObserver = {"observe":function() { - var string = Zotero.File.getContents(_tmpFile); + var _integrationPipeObserver = {"observe":function(subject) { + // if we had an error reading from the pipe, return immediately, because trying to read + // again will probably just cause us to loop + if(subject.exitValue !== 0) { + Components.utils.reportError("Zotero: An error occurred reading from integration pipe"); + return; + } + // read from pipe + var string = Zotero.File.getContents(_tmpFile); if(string != "") { + // exec command if possible var parts = string.match(/^([^ \n]*) ([^ \n]*)(?: ([^\n]*))?\n?$/); if(parts) { var agent = parts[1].toString(); var cmd = parts[2].toString(); - var document = parts[3] ? parts[3].toString() : null; - // remove temp file and halt reading on shutdown - if(agent === "Zotero" && cmd === "shutdown") { - _tmpFile.remove(); - return; - } + // return if we were told to shutdown + if(agent === "Zotero" && cmd === "shutdown") return; + + // set up another process to read from the pipe + _shProc.runAsync(_shCmd, _shCmd.length, _integrationPipeObserver); + var document = parts[3] ? parts[3].toString() : null; Zotero.Integration.execCommand(agent, cmd, document); } else { - Components.utils.reportError("Integration Worker: Invalid input received: "+string); + // set up another process to read from the pipe + _shProc.runAsync(_shCmd, _shCmd.length, _integrationPipeObserver); + Components.utils.reportError("Zotero: Invalid integration input received: "+string); } + } else { + // set up another process to read from the pipe + _shProc.runAsync(_shCmd, _shCmd.length, _integrationPipeObserver); } - - _shProc.runAsync(_shCmd, _shCmd.length, _integrationPipeObserver); }}; /** @@ -371,6 +382,7 @@ Zotero.Integration = new function() { oStream.write(cmd, cmd.length); oStream.close(); _fifoFile.remove(false); + _tmpFile.remove(false); } /**