Mendeley Import: Prevent tmp path > 260 chars
This commit is contained in:
parent
63205a73e8
commit
7582147dd5
1 changed files with 12 additions and 2 deletions
|
@ -706,8 +706,18 @@ Zotero_Import_Mendeley.prototype._getDocumentFilesAPI = async function (document
|
||||||
for (let doc of documents) {
|
for (let doc of documents) {
|
||||||
const files = [];
|
const files = [];
|
||||||
for (let file of (doc.files || [])) {
|
for (let file of (doc.files || [])) {
|
||||||
const fileName = Zotero.File.getValidFileName(file.file_name || 'file');
|
var fileName = Zotero.File.truncateFileName(Zotero.File.getValidFileName(file.file_name || 'file'), 255); // most filesystems limit filename to 255 characters
|
||||||
const tmpFile = OS.Path.join(Zotero.getTempDirectory().path, `m-api-${this.timestamp}-${file.id}`, fileName);
|
var tmpFile = OS.Path.join(Zotero.getTempDirectory().path, `m-api-${this.timestamp}-${file.id}`, fileName);
|
||||||
|
if (tmpFile.length >= 260) {
|
||||||
|
const surplus = tmpFile.length - 260;
|
||||||
|
if (surplus >= fileName.length) {
|
||||||
|
Zotero.logError(`File ${fileName} will be skipped due to path exceeding filesystem limits: ${tmpFile}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Zotero.debug(`${fileName} will be truncated by ${surplus} characters`);
|
||||||
|
fileName = Zotero.File.truncateFileName(fileName, fileName.length - surplus);
|
||||||
|
tmpFile = OS.Path.join(Zotero.getTempDirectory().path, `m-api-${this.timestamp}-${file.id}`, fileName);
|
||||||
|
}
|
||||||
this._tmpFilesToDelete.push(tmpFile);
|
this._tmpFilesToDelete.push(tmpFile);
|
||||||
caller.add(this._fetchFile.bind(this, file.id, tmpFile));
|
caller.add(this._fetchFile.bind(this, file.id, tmpFile));
|
||||||
files.push({
|
files.push({
|
||||||
|
|
Loading…
Reference in a new issue