From e8b5751c1f505e1c3ed51d745da39134b84146d2 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 20 Sep 2008 12:51:19 +0000 Subject: [PATCH] fix filename path construction in io.createTempFile and try TMPDIR as a possible location for the temp file --- content/io.js | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/content/io.js b/content/io.js index 6d3495fa..4a0e86e2 100644 --- a/content/io.js +++ b/content/io.js @@ -471,36 +471,38 @@ liberator.IO = function () //{{{ // returns a nsILocalFile or null if it could not be created createTempFile: function () { - var file = Components.classes["@mozilla.org/file/local;1"] + let file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); + let tmpName = extname + ".tmp"; - var tmpname = liberator.config.name.toLowerCase() + "-"; - try { - if (window.content.document.location.hostname) - tmpname += window.content.document.location.hostname; - } - catch (e) {} - tmpname += ".tmp"; - - if (liberator.config.name == "Muttator") - tmpname = "mutt-ator-mail"; // to allow vim to :set ft=mail automatically - - if (WINDOWS) + switch (extname) { - var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "C:\\"; - file.initWithPath(dir + tmpname); - } - else - { - var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "/tmp/"; - file.initWithPath(dir + tmpname); + case "muttator": + tmpName = "mutt-ator-mail"; // to allow vim to :set ft=mail automatically + break; + case "vimperator": + try + { + if (window.content.document.location.hostname) + tmpName = extname + "-" + window.content.document.location.hostname + ".tmp"; + } + catch (e) {} + break; } + // TODO: Should we by trying /tmp first like Vim? + let dir = environmentService.get("TMPDIR") || environmentService.get("TMP") + || environmentService.get("TEMP") || (WINDOWS ? "C:\\" : "/tmp/"); + + file.initWithPath(dir) + file.appendRelativePath(tmpName); file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600); - if (!file.exists()) - return null; - return file; + if (file.exists()) + return file; + else + return null; // XXX + }, // file is either a full pathname or an instance of file instanceof nsILocalFile