Be sure to clean up temp attachment storage dir in importFromDocument()

This commit is contained in:
Dan Stillman 2016-06-02 16:04:32 -04:00
parent fcb6e0c068
commit 37063f639f

View file

@ -566,6 +566,7 @@ Zotero.Attachments = new function(){
} }
var tmpDir = yield this.createTemporaryStorageDirectory(); var tmpDir = yield this.createTemporaryStorageDirectory();
try {
var tmpFile = tmpDir.clone(); var tmpFile = tmpDir.clone();
var fileName = Zotero.File.truncateFileName(_getFileNameFromURL(url, contentType), 100); var fileName = Zotero.File.truncateFileName(_getFileNameFromURL(url, contentType), 100);
tmpFile.append(fileName); tmpFile.append(fileName);
@ -616,10 +617,6 @@ Zotero.Attachments = new function(){
else if (parentItemID) { else if (parentItemID) {
let {libraryID: parentLibraryID, key: parentKey} = let {libraryID: parentLibraryID, key: parentKey} =
Zotero.Items.getLibraryAndKeyFromID(parentItemID); Zotero.Items.getLibraryAndKeyFromID(parentItemID);
Zotero.debug('==-=');
Zotero.debug(parentItemID);
Zotero.debug(parentLibraryID);
Zotero.debug(parentKey);
attachmentItem.libraryID = parentLibraryID; attachmentItem.libraryID = parentLibraryID;
} }
attachmentItem.setField('title', title); attachmentItem.setField('title', title);
@ -642,8 +639,9 @@ Zotero.Attachments = new function(){
attachmentItem.attachmentPath = destFile.path; attachmentItem.attachmentPath = destFile.path;
yield attachmentItem.save(); yield attachmentItem.save();
}.bind(this)) }.bind(this));
.catch(function (e) { }
catch (e) {
Zotero.debug(e, 1); Zotero.debug(e, 1);
// Clean up // Clean up
@ -660,7 +658,7 @@ Zotero.Attachments = new function(){
} }
throw e; throw e;
}); }
// We don't have any way of knowing that the file is flushed to disk, // We don't have any way of knowing that the file is flushed to disk,
// so we just wait a second before indexing and hope for the best. // so we just wait a second before indexing and hope for the best.