From 4bc779fe7cce674da2804e7d88491eef6247da59 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 6 Oct 2011 02:22:50 -0400 Subject: [PATCH] Better temp file names for gF and friends. --- common/modules/buffer.jsm | 5 ++++- common/modules/config.jsm | 2 +- common/modules/io.jsm | 9 ++++----- pentadactyl/content/config.js | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 962ac352..1c20a89f 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -1016,6 +1016,9 @@ var Buffer = Module("Buffer", { }; let uri = isString(doc) ? util.newURI(doc) : util.newURI(doc.location.href); + let ext = uri.fileExtension || "txt"; + if (doc.contentType) + ext = services.mime.getPrimaryExtension(doc.contentType, ext); if (!isString(doc)) return io.withTempFiles(function (temp) { @@ -1023,7 +1026,7 @@ var Buffer = Module("Buffer", { encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted); temp.write(encoder.encodeToString(), ">"); return this.callback(temp, true); - }, this, true); + }, this, true, ext); let file = util.getFile(uri); if (file) diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 5ebd0ef8..930b24e5 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -569,7 +569,7 @@ var ConfigBase = Class("ConfigBase", { * @property {string} The leaf name of any temp files created by * {@link io.createTempFile}. */ - get tempFile() this.name + ".tmp", + get tempFile() this.name + ".txt", /** * @constant diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 29457613..68afa889 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -326,7 +326,6 @@ var IO = Module("io", { return null; }, - // TODO: make secure /** * Creates a temporary file. * @@ -337,7 +336,7 @@ var IO = Module("io", { var file = name.clone(); else { file = services.directory.get("TmpD", Ci.nsIFile); - file.append(name || config.addon.name); + file.append(this.config.tempFile + (name ? "." + name : "")); } file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600)); @@ -502,7 +501,7 @@ var IO = Module("io", { let { shellEscape } = util.closure; - return this.withTempFiles(function (stdin, stdout, cmd) { + return this.ext, withTempFiles(function (stdin, stdout, cmd) { if (input instanceof File) stdin = input; else if (input) @@ -556,8 +555,8 @@ var IO = Module("io", { * @returns {boolean} false if temp files couldn't be created, * otherwise, the return value of *func*. */ - withTempFiles: function withTempFiles(func, self, checked) { - let args = array(util.range(0, func.length)).map(this.closure.createTempFile).array; + withTempFiles: function withTempFiles(func, self, checked, ext) { + let args = array(util.range(0, func.length)).map(bind("createTempFile", this, ext)).array; try { if (!args.every(util.identity)) return false; diff --git a/pentadactyl/content/config.js b/pentadactyl/content/config.js index 490a7911..c9ae10b3 100644 --- a/pentadactyl/content/config.js +++ b/pentadactyl/content/config.js @@ -86,7 +86,7 @@ var Config = Module("config", ConfigBase, { } catch (e) {} - return prefix + ".tmp"; + return prefix + ".txt"; } })