Properly rename attachments when filenames differ only in case

This might have been limited to case-insensitive filesystems.

Also fix renaming when the previous filename didn't include an
extension. Before, a file named "test" would be renamed from parent with
".test" as the extension.
This commit is contained in:
Dan Stillman 2012-04-04 04:44:04 -04:00
parent ca8ac7b817
commit 68073b8b32
2 changed files with 14 additions and 8 deletions

View file

@ -2742,15 +2742,21 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
// Ignore if no change
//
// Note: Just comparing file.leafName to newName isn't reliable
if (file.leafName == dest.leafName) {
if (file.leafName === dest.leafName) {
return true;
}
if (overwrite) {
dest.remove(false);
}
else if (dest.exists()) {
return -1;
// If old and new names differ only in case, let's bank on this
// just being a case change and not bother checking for existing
// files, since dest.exists() will just show true on a case-insensitive
// filesystem anyway.
if (file.leafName.toLowerCase() != dest.leafName.toLowerCase()) {
if (overwrite) {
dest.remove(false);
}
else if (dest.exists()) {
return -1;
}
}
file.moveTo(null, newName);

View file

@ -3684,9 +3684,9 @@ var ZoteroPane = new function()
var parentItemID = item.getSource();
var newName = Zotero.Attachments.getFileBaseNameFromItem(parentItemID);
var ext = file.leafName.match(/[^\.]+$/);
var ext = file.leafName.match(/\.[^\.]+$/);
if (ext) {
newName = newName + '.' + ext;
newName = newName + ext;
}
var renamed = item.renameAttachmentFile(newName);