Bug 1677088 - remove EngimailFiles tempdir handling. r=PatrickBrunschwig

Remove temp dir handling (temp dir must always exist), and also a few other methods never used anymore.

Differential Revision: https://phabricator.services.mozilla.com/D128043

--HG--
extra : rebase_source : db9e4fb846a1dbdff965cbc3f9ade4d5c3e59e79
This commit is contained in:
Magnus Melin 2021-10-11 09:19:52 +03:00
Родитель b81182c757
Коммит 819075427f
7 изменённых файлов: 10 добавлений и 218 удалений

Просмотреть файл

@ -1301,17 +1301,7 @@ function openPgpCopyToClipboard(val) {
* @param {string} keyId - The formatted OpenPgp Key ID.
*/
function openPgpSendKeyEmail(keyId) {
let tmpDir = EnigmailFiles.getTempDir();
let tmpFile;
try {
tmpFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
tmpFile.initWithPath(tmpDir);
} catch (ex) {
Cu.reportError(ex);
return;
}
let tmpFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
tmpFile.append("key.asc");
tmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);

Просмотреть файл

@ -27,66 +27,6 @@ const NS_TRUNCATE = 0x20;
const DEFAULT_FILE_PERMS = 0o600;
var EnigmailFiles = {
isAbsolutePath(filePath, isDosLike) {
// Check if absolute path
if (isDosLike) {
return (
filePath.search(/^\w+:\\/) === 0 ||
filePath.search(/^\\\\/) === 0 ||
filePath.search(/^\/\//) === 0
);
}
return filePath.search(/^\//) === 0;
},
resolvePath(filePath, envPath, isDosLike) {
EnigmailLog.DEBUG("files.jsm: resolvePath: filePath=" + filePath + "\n");
if (EnigmailFiles.isAbsolutePath(filePath, isDosLike)) {
return filePath;
}
if (!envPath) {
return null;
}
const fileNames = filePath.split(";");
const pathDirs = envPath.split(isDosLike ? ";" : ":");
for (let i = 0; i < fileNames.length; i++) {
for (let j = 0; j < pathDirs.length; j++) {
try {
const pathDir = Cc["@mozilla.org/file/local;1"].createInstance(
Ci.nsIFile
);
EnigmailLog.DEBUG(
"files.jsm: resolvePath: checking for " +
pathDirs[j] +
"/" +
fileNames[i] +
"\n"
);
EnigmailFiles.initPath(pathDir, pathDirs[j]);
try {
if (pathDir.exists() && pathDir.isDirectory()) {
pathDir.appendRelativePath(fileNames[i]);
if (pathDir.exists() && !pathDir.isDirectory()) {
return pathDir;
}
}
} catch (ex) {}
} catch (ex) {}
}
}
return null;
},
createFileStream(filePath, permissions) {
try {
let localFile;
@ -200,30 +140,6 @@ var EnigmailFiles = {
return fileContents;
},
formatCmdLine(command, args) {
function getQuoted(str) {
str = str.toString();
let i = str.indexOf(" ");
if (i >= 0) {
return '"' + str + '"';
}
return str;
}
if (command instanceof Ci.nsIFile) {
command = EnigmailFiles.getFilePathDesc(command);
}
const cmdStr = getQuoted(command) + " ";
const argStr = args
.map(getQuoted)
.join(" ")
.replace(/\\\\/g, "\\");
return cmdStr + argStr;
},
getFilePathDesc(nsFileObj) {
if (AppConstants.platform == "win") {
return nsFileObj.persistentDescriptor;
@ -232,13 +148,6 @@ var EnigmailFiles = {
return nsFileObj.path;
},
getFilePath(nsFileObj) {
return EnigmailData.convertToUnicode(
EnigmailFiles.getFilePathDesc(nsFileObj),
"utf-8"
);
},
getEscapedFilename(fileNameStr) {
if (AppConstants.platform == "win") {
// escape the backslashes and the " character (for Windows)
@ -250,63 +159,6 @@ var EnigmailFiles = {
return fileNameStr;
},
/**
* get the temporary folder
*
* @return nsIFile object holding a reference to the temp directory
*/
getTempDirObj() {
const TEMPDIR_PROP = "TmpD";
try {
const dsprops = Cc["@mozilla.org/file/directory_service;1"]
.getService()
.QueryInterface(Ci.nsIProperties);
return dsprops.get(TEMPDIR_PROP, Ci.nsIFile);
} catch (ex) {
// let's guess ...
const tmpDirObj = Cc["@mozilla.org/file/local;1"].createInstance(
Ci.nsIFile
);
if (AppConstants.platform == "win") {
tmpDirObj.initWithPath("C:/TEMP");
} else {
tmpDirObj.initWithPath("/tmp");
}
return tmpDirObj;
}
},
/**
* get the temporary folder as string
*
* @return String containing the temp directory name
*/
getTempDir() {
return EnigmailFiles.getTempDirObj().path;
},
/**
* create a new folder as subfolder of the temporary directory
*
* @param dirName String - name of subfolder
* @param unique Boolean - if true, the directory is guaranteed to be unique
*
* @return nsIFile object holding a reference to the created directory
*/
createTempSubDir(dirName, unique = false) {
const localFile = EnigmailFiles.getTempDirObj().clone();
localFile.append(dirName);
if (unique) {
localFile.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 509 /* = 0775 */);
} else {
localFile.create(Ci.nsIFile.DIRECTORY_TYPE, 509 /* = 0775 */);
}
return localFile;
},
/**
* Ensure that a directory exists and is writeable.
*

Просмотреть файл

@ -35,7 +35,7 @@ var EnigmailSend = {
EnigmailLog.DEBUG("EnigmailSend.sendMessage()\n");
let tmpFile, msgIdentity;
try {
tmpFile = EnigmailFiles.getTempDirObj();
tmpFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
tmpFile.append("message.eml");
tmpFile.createUnique(0, 0o600);
} catch (ex) {

Просмотреть файл

@ -420,18 +420,7 @@ function enigmailDeleteKey() {
function enigCreateKeyMsg() {
var keyList = getSelectedKeyIds();
var tmpDir = EnigmailFiles.getTempDir();
var tmpFile;
try {
tmpFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
tmpFile.initWithPath(tmpDir);
if (!(tmpFile.isDirectory() && tmpFile.isWritable())) {
document.l10n.formatValue("no-temp-dir").then(value => {
EnigmailDialog.alert(window, value);
});
return;
}
} catch (ex) {}
var tmpFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
tmpFile.append("key.asc");
tmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);

Просмотреть файл

@ -2494,14 +2494,7 @@ Enigmail.msg = {
}
// open
var tmpDir = EnigmailFiles.getTempDir();
var outFile1, outFile2;
outFile1 = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
outFile1.initWithPath(tmpDir);
if (!(outFile1.isDirectory() && outFile1.isWritable())) {
EnigmailDialog.alert(window, l10n.formatValueSync("no-temp-dir"));
return;
}
var outFile1 = Services.dirsvc.get("TmpD", Ci.nsIFile);
outFile1.append(EnigmailMsgRead.getAttachmentName(origAtt));
outFile1.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
EnigmailFiles.writeUrlToFile(origAtt.url, outFile1);
@ -2519,8 +2512,7 @@ Enigmail.msg = {
);
}
outFile2 = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
outFile2.initWithPath(tmpDir);
var outFile2 = Services.dirsvc.get("TmpD", Ci.nsIFile);
outFile2.append(EnigmailMsgRead.getAttachmentName(signatureAtt));
outFile2.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
EnigmailFiles.writeUrlToFile(signatureAtt.url, outFile2);
@ -2662,20 +2654,9 @@ Enigmail.msg = {
return;
} else {
// open
var tmpDir = EnigmailFiles.getTempDir();
try {
outFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
outFile.initWithPath(tmpDir);
if (!(outFile.isDirectory() && outFile.isWritable())) {
errorMsgObj.value = l10n.formatValueSync("no-temp-dir");
return;
}
outFile.append(rawFileName);
outFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
} catch (ex) {
errorMsgObj.value = l10n.formatValueSync("no-temp-dir");
return;
}
outFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
outFile.append(rawFileName);
outFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
}
if (callbackArg.actionType == "importKey") {

Просмотреть файл

@ -793,23 +793,7 @@ Enigmail.msg = {
return null;
}
var tmpDir = EnigmailFiles.getTempDir();
var tmpFile;
try {
tmpFile = Cc[LOCAL_FILE_CONTRACTID].createInstance(Ci.nsIFile);
tmpFile.initWithPath(tmpDir);
if (!(tmpFile.isDirectory() && tmpFile.isWritable())) {
document.l10n.formatValue("no-temp-dir").then(value => {
EnigmailDialog.alert(window, value);
});
return null;
}
} catch (ex) {
EnigmailLog.writeException(
"enigmailMsgComposeOverlay.js: Enigmail.msg.extractAndAttachKey",
ex
);
}
var tmpFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
tmpFile.append("key.asc");
tmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
@ -832,8 +816,7 @@ Enigmail.msg = {
}
// create attachment
var ioServ = Services.io;
var tmpFileURI = ioServ.newFileURI(tmpFile);
var tmpFileURI = Services.io.newFileURI(tmpFile);
var keyAttachment = Cc[
"@mozilla.org/messengercompose/attachment;1"
].createInstance(Ci.nsIMsgAttachment);

Просмотреть файл

@ -662,9 +662,6 @@ send-to-news-warning =
This is discouraged because it only makes sense if all members of the group can decrypt the message, i.e. the message needs to be encrypted with the keys of all group participants. Please send this message only if you know exactly what you are doing.
Continue?
save-attachment-header = Save decrypted attachment
no-temp-dir =
Could not find a temporary directory to write to
Please set the TEMP environment variable
possibly-pgp-mime = Possibly PGP/MIME encrypted or signed message; use Decrypt/Verify function to verify
cannot-send-sig-because-no-own-key = Cannot digitally sign this message, because you havent yet configured end-to-end encryption for <{ $key }>
cannot-send-enc-because-no-own-key = Cannot send this message encrypted, because you havent yet configured end-to-end encryption for <{ $key }>