Skip to content

Commit

Permalink
fix bug: subfolder duplicates in renamed attachment's name when set d…
Browse files Browse the repository at this point in the history
…isable_renaming=true (jlegewie#200)
  • Loading branch information
hyliang96 committed Dec 9, 2019
1 parent 88bf093 commit e7ee112
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions chrome/content/zotfile/zotfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Zotero.ZotFile = new function() {
}
// set to pdf.js if poppler is not supported
if(!this.pdfAnnotations.popplerExtractorSupported) this.setPref('pdfExtraction.UsePDFJS', true);

}.bind(this));
}
// Register callbacks in Zotero as item observers
Expand All @@ -109,7 +109,7 @@ Zotero.ZotFile = new function() {
window.addEventListener('unload', function(e) {
Zotero.Notifier.unregisterObserver(Zotero.ZotFile.notifierID);
Zotero.ZotFile.notifierID = null;
}, false);
}, false);
// Load zotero.js first
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
Expand Down Expand Up @@ -162,7 +162,7 @@ Zotero.ZotFile = new function() {
* @param {string} pref Name of preference in 'extensions.zotfile' branch
* @param {string|int|bool} value Value of preference
*/
this.setPref = function(pref, value) {
this.setPref = function(pref, value) {
Zotero.Prefs.set('extensions.zotfile.' + pref, value, true);
};

Expand Down Expand Up @@ -295,7 +295,7 @@ Zotero.ZotFile = new function() {
errors.lines.push(this.ZFgetString('error.unknown'));
errors.txt = this.ZFgetString('error.clickToCopy');
// prepare error message for clipboard

var errors_str = this.messages_fatalError.map(function(e) {
if (typeof e == 'object') Zotero.logError(e);
return typeof e == 'object' ? this.format_error(e) : e;
Expand Down Expand Up @@ -371,7 +371,7 @@ Zotero.ZotFile = new function() {

return(button);

};
};

this.addUserInput = function(filename, original_filename){
var default_str = this.getPref('userInput_Default');
Expand Down Expand Up @@ -495,13 +495,13 @@ Zotero.ZotFile = new function() {
Zotero.debug("Attachment file not found in moveLinkedAttachmentFile()", 2);
return false;
}

try {
var origName = OS.Path.basename(origPath);
var origModDate = (yield OS.File.stat(origPath)).lastModificationDate;

filename = Zotero.File.getValidFileName(filename);

var destPath = OS.Path.join(location, filename);
var destName = OS.Path.basename(destPath);

Expand All @@ -510,7 +510,7 @@ Zotero.ZotFile = new function() {
Zotero.debug("Filename has not changed");
return true;
}

destPath = yield this.moveFile(origPath, destPath);
yield att.relinkAttachmentFile(destPath);
return true;
Expand Down Expand Up @@ -883,12 +883,12 @@ Zotero.ZotFile = new function() {
att_note = att.getNote(),
att_tags = att.getTags(),
att_relations = att.getRelations();
if (!path) throw('Zotero.ZotFile.renameAttachment(): Attachment file does not exists.');
if (!path) throw('Zotero.ZotFile.renameAttachment(): Attachment file does not exists.');
// only proceed if linked or imported attachment
if(!att.isImportedAttachment() && !linkmode == Zotero.Attachments.LINK_MODE_LINKED_FILE)
return att;
// get filename and location
var filename = rename ? this.getFilename(item, att.attachmentFilename) : att.attachmentFilename,
var filename = rename ? this.getFilename(item, OS.Path.basename(att.attachmentFilename)) : OS.Path.basename(att.attachmentFilename),
location = this.getLocation(folder, item, subfolder);
// (a) linked to imported attachment
if (imported && linkmode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
Expand Down Expand Up @@ -991,10 +991,10 @@ Zotero.ZotFile = new function() {
var atts = Zotero.Items.get(this.getSelectedAttachments())
.filter(this.checkFileType);
// confirm renaming
if (this.getPref('confirmation_batch_ask') && atts.length >= this.getPref('confirmation_batch'))
if (this.getPref('confirmation_batch_ask') && atts.length >= this.getPref('confirmation_batch'))
if(!confirm(this.ZFgetString('renaming.moveRename', [atts.length])))
return;
// show infoWindow
// show infoWindow
var progressWin = this.progressWindow(this.ZFgetString('renaming.renamed')),
description = atts.length == 0;
// rename attachments
Expand Down

0 comments on commit e7ee112

Please sign in to comment.