www

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

commit 3655c0945048b10ec3d71c26f1a1c55d07afc9cc
parent 66ca2cfda2f0e172200d3198d20032f36dfe282a
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 19 Jul 2016 18:48:55 -0400

Zotero.Item.prototype.deleteAttachmentFile()

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -2564,6 +2564,31 @@ Zotero.Item.prototype.relinkAttachmentFile = Zotero.Promise.coroutine(function* }); +Zotero.Item.prototype.deleteAttachmentFile = Zotero.Promise.coroutine(function* () { + if (!this.isImportedAttachment()) { + throw new Error("deleteAttachmentFile() can only be called on imported attachment items"); + } + + var path = yield this.getFilePathAsync(); + if (!path) { + Zotero.debug(`File not found for item ${this.libraryKey} in deleteAttachmentFile()`, 2); + return false; + } + + Zotero.debug("Deleting attachment file for item " + this.libraryKey); + try { + yield Zotero.File.removeIfExists(path); + this.attachmentSyncState = "to_download"; + yield this.saveTx({ skipAll: true }); + return true; + } + catch (e) { + Zotero.logError(e); + return false; + } +}); + + /* * Return a file:/// URL path to files and snapshots