1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-23 06:33:33 +01:00

fix filename path construction in io.createTempFile and try TMPDIR as a

possible location for the temp file
This commit is contained in:
Doug Kearns
2008-09-20 12:51:19 +00:00
parent ef1c96ae03
commit e8b5751c1f

View File

@@ -471,36 +471,38 @@ liberator.IO = function () //{{{
// returns a nsILocalFile or null if it could not be created // returns a nsILocalFile or null if it could not be created
createTempFile: function () createTempFile: function ()
{ {
var file = Components.classes["@mozilla.org/file/local;1"] let file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile); .createInstance(Components.interfaces.nsILocalFile);
let tmpName = extname + ".tmp";
var tmpname = liberator.config.name.toLowerCase() + "-"; switch (extname)
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)
{ {
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "C:\\"; case "muttator":
file.initWithPath(dir + tmpname); tmpName = "mutt-ator-mail"; // to allow vim to :set ft=mail automatically
} break;
else case "vimperator":
{ try
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "/tmp/"; {
file.initWithPath(dir + tmpname); 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); 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 // file is either a full pathname or an instance of file instanceof nsILocalFile