www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 68073b8b32136e438760f5a460fdcf93ee3e3581
parent ca8ac7b81741a121ca2c8fb6c79b1e957233f8f3
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed,  4 Apr 2012 04:44:04 -0400

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.

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 18++++++++++++------
Mchrome/content/zotero/zoteroPane.js | 4++--
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -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); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -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);