Mendeley import: Move temp downloaded files instead of copying #2149 (#2150)

During Mendeley api import all attachments are fetched into temporary
location and were previously copied to the storage folder. Only after
import completed, temporary files were deleted. Therefore a complete
import required storage equal to twice the final library size. Switching
to move avoids this problem.

Also:

- Fix _isTempDownloadedFile() check
This commit is contained in:
Tom Najdek 2021-08-20 06:07:28 +02:00 committed by GitHub
parent ddc7be75c7
commit f274323478
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -1410,6 +1410,8 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
// If we're not set to link files or file is in Mendeley downloads folder, import it
if (!this._linkFiles || this._isDownloadedFile(path) || this._isTempDownloadedFile(path)) {
options.moveFile = this._isTempDownloadedFile(path);
if (file.url) {
options.title = file.title;
options.url = file.url;
@ -1480,8 +1482,7 @@ Zotero_Import_Mendeley.prototype._isDownloadedFile = function (path) {
}
Zotero_Import_Mendeley.prototype._isTempDownloadedFile = function (path) {
var parentDir = OS.Path.dirname(path);
return parentDir.startsWith(OS.Path.join(Zotero.getTempDirectory().path, 'm-api'));
return path.startsWith(OS.Path.join(Zotero.getTempDirectory().path, 'm-api'));
};
/**

View file

@ -109,8 +109,14 @@ Zotero.Attachments = new function(){
// Point to copied file
newFile = OS.Path.join(destDir, newName);
// Copy file to unique filename, which automatically shortens long filenames
newFile = Zotero.File.copyToUnique(file, newFile);
// Copy or move file to unique filename, which automatically shortens long filenames
if (options.moveFile) {
const newFilePath = yield Zotero.File.moveToUnique(file.path, newFile);
newFile = Zotero.File.pathToFile(newFilePath);
}
else {
newFile = Zotero.File.copyToUnique(file, newFile);
}
yield Zotero.File.setNormalFilePermissions(newFile.path);
@ -315,7 +321,12 @@ Zotero.Attachments = new function(){
// Copy single file to new directory
if (options.singleFile) {
yield this.createDirectoryForItem(attachmentItem);
yield OS.File.copy(file.path, newPath);
if (options.moveFile) {
yield OS.File.move(file.path, newPath);
}
else {
yield OS.File.copy(file.path, newPath);
}
}
// Copy entire parent directory (for HTML snapshots)
else {