1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-26 03:32:27 +01:00

Better temp file names for gF and friends.

This commit is contained in:
Kris Maglione
2011-10-06 02:22:50 -04:00
parent adea42d882
commit 4bc779fe7c
4 changed files with 10 additions and 8 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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;