- Renaming an attachment file with certain extended characters could cause it to be deleted
- When relinking a file, automatically rename file with cross-platform invalid characters (e.g., "/") filtered out
This commit is contained in:
parent
af3ef422a3
commit
ecaa599bec
2 changed files with 25 additions and 6 deletions
|
@ -409,7 +409,11 @@
|
|||
if (checkState.value) {
|
||||
var renamed = item.renameAttachmentFile(newTitle.value);
|
||||
if (renamed == -1) {
|
||||
var confirmed = confirm(newTitle.value + ' exists. Overwrite existing file?');
|
||||
var confirmed = nsIPS.confirm(
|
||||
window,
|
||||
'',
|
||||
newTitle.value + ' exists. Overwrite existing file?'
|
||||
);
|
||||
if (confirmed) {
|
||||
item.renameAttachmentFile(newTitle.value, true);
|
||||
break;
|
||||
|
|
|
@ -2592,15 +2592,18 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
|
|||
try {
|
||||
newName = Zotero.File.getValidFileName(newName);
|
||||
|
||||
if (file.leafName == newName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var dest = file.parent;
|
||||
dest.append(newName);
|
||||
|
||||
// Ignore if no change
|
||||
//
|
||||
// Note: Just comparing file.leafName to newName isn't reliable
|
||||
if (file.leafName == dest.leafName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (overwrite) {
|
||||
dest.remove(null);
|
||||
dest.remove(false);
|
||||
}
|
||||
else if (dest.exists()) {
|
||||
return -1;
|
||||
|
@ -2635,9 +2638,21 @@ Zotero.Item.prototype.relinkAttachmentFile = function(file) {
|
|||
throw('Cannot relink linked URL in Zotero.Items.relinkAttachmentFile()');
|
||||
}
|
||||
|
||||
var newName = Zotero.File.getValidFileName(file.leafName);
|
||||
if (!newName) {
|
||||
throw ("No valid characters in filename after filtering in Zotero.Item.relinkAttachmentFile()");
|
||||
}
|
||||
|
||||
// Rename file to filtered name if necessary
|
||||
if (file.leafName != newName) {
|
||||
Zotero.debug("Renaming file '" + file.leafName + "' to '" + newName + "'");
|
||||
file.moveTo(null, newName);
|
||||
}
|
||||
|
||||
var path = Zotero.Attachments.getPath(file, linkMode);
|
||||
this.attachmentPath = path;
|
||||
this.save();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue