www

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

commit 7677eccb9f3cc4930e426ed3bff0f6dc9ae2534e
parent 500076ea63a814dbeed082d36ac81005269ba1ac
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed, 17 Apr 2013 16:13:02 -0400

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.

Diffstat:
Mchrome/content/zotero/xpcom/attachments.js | 5+++--
Mchrome/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 @@ -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 @@ -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; }