Mendeley import: Fix duplicate PDF copying for PDFs in Downloaded
For each PDF with an associated URL in the Downloaded directory, we were copying all files in the directory (!) to the attachment's storage directory. (Zotero imports always have files in separate directories, and this was a function used to save both single files and HTML snapshots.) We'll clean up the extra files in a separate step.
This commit is contained in:
parent
68d03bc6c3
commit
cdee741a6d
2 changed files with 24 additions and 9 deletions
|
@ -983,6 +983,7 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
|
|||
options.title = file.title;
|
||||
options.url = file.url;
|
||||
options.contentType = file.contentType;
|
||||
options.singleFile = true;
|
||||
attachment = await Zotero.Attachments.importSnapshotFromFile(options);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -176,14 +176,18 @@ Zotero.Attachments = new function(){
|
|||
|
||||
|
||||
/**
|
||||
* @param {Object} options - 'file', 'url', 'title', 'contentType', 'charset', 'parentItemID'
|
||||
* @param {Object} options - 'file', 'url', 'title', 'contentType', 'charset', 'parentItemID', 'singleFile'
|
||||
* @return {Promise<Zotero.Item>}
|
||||
*/
|
||||
this.importSnapshotFromFile = Zotero.Promise.coroutine(function* (options) {
|
||||
Zotero.debug('Importing snapshot from file');
|
||||
|
||||
var file = Zotero.File.pathToFile(options.file);
|
||||
var fileName = file.leafName;
|
||||
// TODO: Fix main filename when copying directory, though in that case it's probably
|
||||
// from our own export and already clean
|
||||
var fileName = options.singleFile
|
||||
? Zotero.File.getValidFileName(file.leafName)
|
||||
: file.leafName;
|
||||
var url = options.url;
|
||||
var title = options.title;
|
||||
var contentType = options.contentType;
|
||||
|
@ -194,7 +198,7 @@ Zotero.Attachments = new function(){
|
|||
throw new Error("parentItemID not provided");
|
||||
}
|
||||
|
||||
var attachmentItem, itemID, destDir, newFile;
|
||||
var attachmentItem, itemID, destDir, newPath;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
// Create a new attachment
|
||||
|
@ -217,13 +221,23 @@ Zotero.Attachments = new function(){
|
|||
var storageDir = Zotero.getStorageDirectory();
|
||||
destDir = this.getStorageDirectory(attachmentItem);
|
||||
yield OS.File.removeDir(destDir.path);
|
||||
file.parent.copyTo(storageDir, destDir.leafName);
|
||||
|
||||
// Point to copied file
|
||||
newFile = destDir.clone();
|
||||
newFile.append(file.leafName);
|
||||
newPath = OS.Path.join(destDir.path, fileName);
|
||||
// Copy single file to new directory
|
||||
if (options.singleFile) {
|
||||
yield this.createDirectoryForItem(attachmentItem);
|
||||
yield OS.File.copy(file.path, newPath);
|
||||
}
|
||||
// Copy entire parent directory (for HTML snapshots)
|
||||
else {
|
||||
file.parent.copyTo(storageDir, destDir.leafName);
|
||||
}
|
||||
}.bind(this));
|
||||
yield _postProcessFile(attachmentItem, newFile, contentType, charset);
|
||||
yield _postProcessFile(
|
||||
attachmentItem,
|
||||
Zotero.File.pathToFile(newPath),
|
||||
contentType,
|
||||
charset
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
|
|
Loading…
Reference in a new issue