Remove tmp-* directories when attachment download fails. Closes #1128
This commit is contained in:
parent
43dad62150
commit
74d358bd19
|
@ -326,6 +326,7 @@ Zotero.Attachments = new function(){
|
||||||
|
|
||||||
yield deferred.promise;
|
yield deferred.promise;
|
||||||
let sample = yield Zotero.File.getSample(tmpFile);
|
let sample = yield Zotero.File.getSample(tmpFile);
|
||||||
|
try {
|
||||||
if (contentType == 'application/pdf' &&
|
if (contentType == 'application/pdf' &&
|
||||||
Zotero.MIME.sniffForMIMEType(sample) != 'application/pdf') {
|
Zotero.MIME.sniffForMIMEType(sample) != 'application/pdf') {
|
||||||
let errString = "Downloaded PDF did not have MIME type "
|
let errString = "Downloaded PDF did not have MIME type "
|
||||||
|
@ -369,11 +370,8 @@ Zotero.Attachments = new function(){
|
||||||
// Refetch item to update path
|
// Refetch item to update path
|
||||||
attachmentItem.attachmentPath = destFile.path;
|
attachmentItem.attachmentPath = destFile.path;
|
||||||
yield attachmentItem.save(saveOptions);
|
yield attachmentItem.save(saveOptions);
|
||||||
}.bind(this))
|
}.bind(this));
|
||||||
.catch(function (e) {
|
} catch (e) {
|
||||||
Zotero.debug(e, 1);
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
try {
|
try {
|
||||||
if (tmpDir && tmpDir.exists()) {
|
if (tmpDir && tmpDir.exists()) {
|
||||||
tmpDir.remove(true);
|
tmpDir.remove(true);
|
||||||
|
@ -385,9 +383,8 @@ Zotero.Attachments = new function(){
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.debug(e, 1);
|
Zotero.debug(e, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user