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.
This commit is contained in:
parent
500076ea63
commit
7677eccb9f
2 changed files with 5 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue