mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-31 23:42:27 +01:00
Better temp file names for gF and friends.
This commit is contained in:
@@ -1016,6 +1016,9 @@ var Buffer = Module("Buffer", {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let uri = isString(doc) ? util.newURI(doc) : util.newURI(doc.location.href);
|
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))
|
if (!isString(doc))
|
||||||
return io.withTempFiles(function (temp) {
|
return io.withTempFiles(function (temp) {
|
||||||
@@ -1023,7 +1026,7 @@ var Buffer = Module("Buffer", {
|
|||||||
encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted);
|
encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted);
|
||||||
temp.write(encoder.encodeToString(), ">");
|
temp.write(encoder.encodeToString(), ">");
|
||||||
return this.callback(temp, true);
|
return this.callback(temp, true);
|
||||||
}, this, true);
|
}, this, true, ext);
|
||||||
|
|
||||||
let file = util.getFile(uri);
|
let file = util.getFile(uri);
|
||||||
if (file)
|
if (file)
|
||||||
|
|||||||
@@ -569,7 +569,7 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
* @property {string} The leaf name of any temp files created by
|
* @property {string} The leaf name of any temp files created by
|
||||||
* {@link io.createTempFile}.
|
* {@link io.createTempFile}.
|
||||||
*/
|
*/
|
||||||
get tempFile() this.name + ".tmp",
|
get tempFile() this.name + ".txt",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
|
|||||||
@@ -326,7 +326,6 @@ var IO = Module("io", {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: make secure
|
|
||||||
/**
|
/**
|
||||||
* Creates a temporary file.
|
* Creates a temporary file.
|
||||||
*
|
*
|
||||||
@@ -337,7 +336,7 @@ var IO = Module("io", {
|
|||||||
var file = name.clone();
|
var file = name.clone();
|
||||||
else {
|
else {
|
||||||
file = services.directory.get("TmpD", Ci.nsIFile);
|
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));
|
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600));
|
||||||
|
|
||||||
@@ -502,7 +501,7 @@ var IO = Module("io", {
|
|||||||
|
|
||||||
let { shellEscape } = util.closure;
|
let { shellEscape } = util.closure;
|
||||||
|
|
||||||
return this.withTempFiles(function (stdin, stdout, cmd) {
|
return this.ext, withTempFiles(function (stdin, stdout, cmd) {
|
||||||
if (input instanceof File)
|
if (input instanceof File)
|
||||||
stdin = input;
|
stdin = input;
|
||||||
else if (input)
|
else if (input)
|
||||||
@@ -556,8 +555,8 @@ var IO = Module("io", {
|
|||||||
* @returns {boolean} false if temp files couldn't be created,
|
* @returns {boolean} false if temp files couldn't be created,
|
||||||
* otherwise, the return value of *func*.
|
* otherwise, the return value of *func*.
|
||||||
*/
|
*/
|
||||||
withTempFiles: function withTempFiles(func, self, checked) {
|
withTempFiles: function withTempFiles(func, self, checked, ext) {
|
||||||
let args = array(util.range(0, func.length)).map(this.closure.createTempFile).array;
|
let args = array(util.range(0, func.length)).map(bind("createTempFile", this, ext)).array;
|
||||||
try {
|
try {
|
||||||
if (!args.every(util.identity))
|
if (!args.every(util.identity))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ var Config = Module("config", ConfigBase, {
|
|||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|
||||||
return prefix + ".tmp";
|
return prefix + ".txt";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user