From 7677eccb9f3cc4930e426ed3bff0f6dc9ae2534e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 17 Apr 2013 16:13:02 -0400 Subject: [PATCH] Addresses #104, Shorten long filenames on import This fixes the problem for attached files. I assume this is still a problem for importSnapshotFromFile(), which uses copyTo() on a directory. For that we'd need a copyDirectoryToUnique() function that shortened the names of all files in the directory. --- chrome/content/zotero/xpcom/attachments.js | 5 +++-- chrome/content/zotero/xpcom/file.js | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0e10a7465..b5909b609 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -82,14 +82,15 @@ Zotero.Attachments = new function(){ // Create directory for attachment files within storage directory var destDir = this.createDirectoryForItem(itemID); - file.copyTo(destDir, newName); // Point to copied file var newFile = destDir.clone(); newFile.append(newName); - var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile); + // Copy file to unique filename, which automatically shortens long filenames + newFile = Zotero.File.copyToUnique(file, newFile); + var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile); attachmentItem.attachmentMIMEType = mimeType; attachmentItem.attachmentPath = this.getPath(newFile, this.LINK_MODE_IMPORTED_FILE); diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 7383d4572..3e98deef5 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -39,7 +39,6 @@ Zotero.File = new function(){ this.putContents = putContents; this.getValidFileName = getValidFileName; this.truncateFileName = truncateFileName; - this.copyToUnique = this.copyToUnique; this.getCharsetFromFile = getCharsetFromFile; this.addCharsetListener = addCharsetListener; @@ -287,14 +286,14 @@ Zotero.File = new function(){ } - function copyToUnique(file, newFile) { + this.copyToUnique = function (file, newFile) { newFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); var newName = newFile.leafName; newFile.remove(null); // Copy file to unique name file.copyTo(newFile.parent, newName); - return file; + return newFile; }