Fix several automatic relinking regressions due to PathUtils (#4887)
This commit is contained in:
parent
6fe2772318
commit
1c70e53006
1 changed files with 15 additions and 14 deletions
|
@ -5015,7 +5015,14 @@ var ZoteroPane = new function()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let fileExists = await IOUtils.exists(path);
|
let fileExists;
|
||||||
|
try {
|
||||||
|
fileExists = await IOUtils.exists(path);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
fileExists = false;
|
||||||
|
}
|
||||||
|
|
||||||
// If the file is an evicted iCloud Drive file, launch that to trigger a download.
|
// If the file is an evicted iCloud Drive file, launch that to trigger a download.
|
||||||
// As of 10.13.6, launching an .icloud file triggers the download and opens the
|
// As of 10.13.6, launching an .icloud file triggers the download and opens the
|
||||||
|
@ -6080,10 +6087,11 @@ var ZoteroPane = new function()
|
||||||
* @return {Promise<Boolean>} True if relinked successfully or canceled
|
* @return {Promise<Boolean>} True if relinked successfully or canceled
|
||||||
*/
|
*/
|
||||||
this.checkForLinkedFilesToRelink = async function (item) {
|
this.checkForLinkedFilesToRelink = async function (item) {
|
||||||
// Naive split and join implementations that split on any separator and join using forward slashes
|
const PATH_SEP = Zotero.isWin ? '\\' : '/';
|
||||||
// OS.Path methods have different behavior depending on the platform, and a naive approach is good enough here
|
|
||||||
|
// Split on any separator, join with the platform separator for PathUtils
|
||||||
let split = path => path.split(/[/\\]/);
|
let split = path => path.split(/[/\\]/);
|
||||||
let join = (...segments) => segments.join('/');
|
let join = (base, ...segments) => [base.replace(/\//g, PATH_SEP), ...segments].join(PATH_SEP);
|
||||||
|
|
||||||
Zotero.debug('Attempting to relink automatically');
|
Zotero.debug('Attempting to relink automatically');
|
||||||
|
|
||||||
|
@ -6141,11 +6149,6 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
Zotero.debug('Exists! ' + correctedPath);
|
Zotero.debug('Exists! ' + correctedPath);
|
||||||
|
|
||||||
if (Zotero.isWin) {
|
|
||||||
correctedPath = correctedPath.replace(/\//g, '\\');
|
|
||||||
Zotero.debug('Converted back to Windows path: ' + correctedPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
let otherUnlinked = await Zotero.Items.findMissingLinkedFiles(
|
let otherUnlinked = await Zotero.Items.findMissingLinkedFiles(
|
||||||
item.libraryID,
|
item.libraryID,
|
||||||
unNormalizedDirname
|
unNormalizedDirname
|
||||||
|
@ -6159,9 +6162,6 @@ var ZoteroPane = new function()
|
||||||
if (!otherParts.length) continue;
|
if (!otherParts.length) continue;
|
||||||
let otherCorrectedPath = join(basePath, ...otherParts);
|
let otherCorrectedPath = join(basePath, ...otherParts);
|
||||||
if (await IOUtils.exists(otherCorrectedPath)) {
|
if (await IOUtils.exists(otherCorrectedPath)) {
|
||||||
if (Zotero.isWin) {
|
|
||||||
otherCorrectedPath = otherCorrectedPath.replace(/\//g, '\\');
|
|
||||||
}
|
|
||||||
othersToRelink.set(otherItem, otherCorrectedPath);
|
othersToRelink.set(otherItem, otherCorrectedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6173,8 +6173,9 @@ var ZoteroPane = new function()
|
||||||
return true;
|
return true;
|
||||||
case 'all':
|
case 'all':
|
||||||
await item.relinkAttachmentFile(correctedPath);
|
await item.relinkAttachmentFile(correctedPath);
|
||||||
await Promise.all([...othersToRelink]
|
for (let [otherItem, otherCorrectedPath] of othersToRelink) {
|
||||||
.map(([i, p]) => i.relinkAttachmentFile(p)));
|
await otherItem.relinkAttachmentFile(otherCorrectedPath);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
case 'manual':
|
case 'manual':
|
||||||
await this.relinkAttachment(item.id);
|
await this.relinkAttachment(item.id);
|
||||||
|
|
Loading…
Reference in a new issue