Bug 231048 download manager poorly renames existing files by incrementing number suffix

patch by ted.mielczarek@gmail.com r=mconnor a=shaver
This commit is contained in:
timeless%mozdev.org 2005-06-01 13:07:33 +00:00
Родитель 93fcf209d9
Коммит 15365152a0
2 изменённых файлов: 26 добавлений и 15 удалений

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

@ -490,19 +490,24 @@ function getTargetFile(aData, aSniffer, aContentType, aIsDocument, aSkipPrompt,
// mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in // mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in
// If you are updating this code, update that code too! We can't share code // If you are updating this code, update that code too! We can't share code
// here since that code is called in a js component. // here since that code is called in a js component.
var collisionCount = 0;
while (file.exists()) { while (file.exists()) {
var parts = /.+-(\d+)(\..*)?$/.exec(file.leafName); collisionCount++;
if (parts) { if (collisionCount == 1) {
file.leafName = file.leafName.replace(/((\d+)\.)|((\d+)$)/, // Append "(2)" before the last dot in (or at the end of) the filename
function (str, dot, dotNum, noDot, noDotNum, pos, s) { // special case .ext.gz etc files so we don't wind up with .tar(2).gz
return (parseInt(str) + 1) + (dot ? "." : ""); if (file.leafName.match(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i)) {
}); file.leafName = file.leafName.replace(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i, "(2)$&");
}
else {
file.leafName = file.leafName.replace(/(\.[^\.]*)?$/, "(2)$&");
}
} }
else { else {
file.leafName = file.leafName.replace(/\.|$/, "-1$&"); // replace the last (n) in the filename with (n+1)
file.leafName = file.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount+1) + ")");
} }
} }
} }
return file; return file;

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

@ -285,16 +285,22 @@ nsUnknownContentTypeDialog.prototype = {
// toolkit/content/contentAreaUtils.js. // toolkit/content/contentAreaUtils.js.
// If you are updating this code, update that code too! We can't share code // If you are updating this code, update that code too! We can't share code
// here since this is called in a js component. // here since this is called in a js component.
var collisionCount = 0;
while (aLocalFile.exists()) { while (aLocalFile.exists()) {
var parts = /.+-(\d+)(\..*)?$/.exec(aLocalFile.leafName); collisionCount++;
if (parts) { if (collisionCount == 1) {
aLocalFile.leafName = aLocalFile.leafName.replace(/((\d+)\.)|((\d+)$)/, // Append "(2)" before the last dot in (or at the end of) the filename
function (str, dot, dotNum, noDot, noDotNum, pos, s) { // special case .ext.gz etc files so we don't wind up with .tar(2).gz
return (parseInt(str) + 1) + (dot ? "." : ""); if (aLocalFile.leafName.match(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i)) {
}); aLocalFile.leafName = aLocalFile.leafName.replace(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i, "(2)$&");
}
else {
aLocalFile.leafName = aLocalFile.leafName.replace(/(\.[^\.]*)?$/, "(2)$&");
}
} }
else { else {
aLocalFile.leafName = aLocalFile.leafName.replace(/\.|$/, "-1$&"); // replace the last (n) in the filename with (n+1)
aLocalFile.leafName = aLocalFile.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount+1) + ")");
} }
} }
aLocalFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600); aLocalFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);