Bug 1022061 - Downloading files with leading period removes file on disk but doesn't replace it. r=paolo

This commit is contained in:
Awad Mackie 2014-06-06 17:44:00 +01:00
Родитель c4b97191fc
Коммит d89131be3b
1 изменённых файлов: 15 добавлений и 6 удалений

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

@ -308,7 +308,8 @@ nsUnknownContentTypeDialog.prototype = {
// Remove the file so that it's not there when we ensure non-existence later;
// this is safe because for the file to exist, the user would have had to
// confirm that he wanted the file overwritten.
if (result.exists())
// Only remove file if final name exists
if (result.exists() && this.getFinalLeafName(result.leafName) == result.leafName)
result.remove(false);
}
catch (ex) {
@ -342,6 +343,18 @@ nsUnknownContentTypeDialog.prototype = {
}.bind(this)).then(null, Components.utils.reportError);
},
getFinalLeafName: function (aLeafName, aFileExt)
{
// Remove any leading periods, since we don't want to save hidden files
// automatically.
aLeafName = aLeafName.replace(/^\.+/, "");
if (aLeafName == "")
aLeafName = "unnamed" + (aFileExt ? "." + aFileExt : "");
return aLeafName;
},
/**
* Ensures that a local folder/file combination does not already exist in
* the file system (or finds such a combination with a reasonably similar
@ -366,12 +379,8 @@ nsUnknownContentTypeDialog.prototype = {
throw new Components.Exception("Destination directory non-existing or permission error",
Components.results.NS_ERROR_FILE_ACCESS_DENIED);
}
// Remove any leading periods, since we don't want to save hidden files
// automatically.
aLeafName = aLeafName.replace(/^\.+/, "");
if (aLeafName == "")
aLeafName = "unnamed" + (aFileExt ? "." + aFileExt : "");
aLeafName = this.getFinalLeafName(aLeafName, aFileExt);
aLocalFolder.append(aLeafName);
// The following assignment can throw an exception, but