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;
|
||||
}
|
||||
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.
|
||||
// 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
|
||||
*/
|
||||
this.checkForLinkedFilesToRelink = async function (item) {
|
||||
// Naive split and join implementations that split on any separator and join using forward slashes
|
||||
// OS.Path methods have different behavior depending on the platform, and a naive approach is good enough here
|
||||
const PATH_SEP = Zotero.isWin ? '\\' : '/';
|
||||
|
||||
// Split on any separator, join with the platform separator for PathUtils
|
||||
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');
|
||||
|
||||
|
@ -6140,11 +6148,6 @@ var ZoteroPane = new function()
|
|||
throw e;
|
||||
}
|
||||
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(
|
||||
item.libraryID,
|
||||
|
@ -6159,9 +6162,6 @@ var ZoteroPane = new function()
|
|||
if (!otherParts.length) continue;
|
||||
let otherCorrectedPath = join(basePath, ...otherParts);
|
||||
if (await IOUtils.exists(otherCorrectedPath)) {
|
||||
if (Zotero.isWin) {
|
||||
otherCorrectedPath = otherCorrectedPath.replace(/\//g, '\\');
|
||||
}
|
||||
othersToRelink.set(otherItem, otherCorrectedPath);
|
||||
}
|
||||
}
|
||||
|
@ -6173,8 +6173,9 @@ var ZoteroPane = new function()
|
|||
return true;
|
||||
case 'all':
|
||||
await item.relinkAttachmentFile(correctedPath);
|
||||
await Promise.all([...othersToRelink]
|
||||
.map(([i, p]) => i.relinkAttachmentFile(p)));
|
||||
for (let [otherItem, otherCorrectedPath] of othersToRelink) {
|
||||
await otherItem.relinkAttachmentFile(otherCorrectedPath);
|
||||
}
|
||||
return true;
|
||||
case 'manual':
|
||||
await this.relinkAttachment(item.id);
|
||||
|
|
Loading…
Reference in a new issue