Handle invalid path when launching/revealing on macOS (#5485)

This commit is contained in:
Abe Jellinek 2025-08-15 01:29:05 -04:00 • committed by GitHub
parent d69a1a65ee
commit 86f9dd7400
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 3 deletions

View file

@ -5106,12 +5106,15 @@ var ZoteroPane = new function () {
return;
}
let fileExists;
let pathIsValid;
try {
fileExists = await IOUtils.exists(path);
pathIsValid = true;
}
catch (e) {
Zotero.logError(e);
fileExists = false;
pathIsValid = false;
}
// If the file is an evicted iCloud Drive file, launch that to trigger a download.
@ -5120,7 +5123,7 @@ var ZoteroPane = new function () {
// for the original file to exist and then continue with regular file opening below.
//
// To trigger eviction for testing, use Cirrus from https://eclecticlight.co/downloads/
if (!fileExists && Zotero.isMac && isLinkedFile) {
if (!fileExists && pathIsValid && Zotero.isMac && isLinkedFile) {
// Get the path to the .icloud file
let iCloudPath = Zotero.File.getEvictedICloudPath(path);
if (await IOUtils.exists(iCloudPath)) {
@ -5381,10 +5384,21 @@ var ZoteroPane = new function () {
if (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) return;
var path = attachment.getFilePath();
var fileExists = await IOUtils.exists(path);
let fileExists;
let pathIsValid;
try {
fileExists = await IOUtils.exists(path);
pathIsValid = true;
}
catch (e) {
Zotero.logError(e);
fileExists = false;
pathIsValid = false;
}
// If file doesn't exist but an evicted iCloud Drive file does, reveal that instead
if (!fileExists && Zotero.isMac && !attachment.isStoredFileAttachment()) {
if (!fileExists && pathIsValid && Zotero.isMac && !attachment.isStoredFileAttachment()) {
let iCloudPath = Zotero.File.getEvictedICloudPath(path);
if (await IOUtils.exists(iCloudPath)) {
path = iCloudPath;

View file

@ -368,6 +368,25 @@ describe("ZoteroPane", function () {
await zp.viewAttachment(attachment.id);
assert.equal(attachment.attachmentContentType, 'application/epub+zip');
});
it("should handle Windows paths on macOS/Linux", async function () {
if (!Zotero.isMac && !Zotero.isLinux) {
this.skip();
return;
}
let file = getTestDataDirectory();
file.append('test.pdf');
let attachment = await Zotero.Attachments.linkFromFile({ file });
attachment.attachmentPath = 'C:\\some\\windows\\path';
await attachment.saveTx();
let stub = sinon.stub(zp, 'showAttachmentNotFoundDialog');
await zp.viewAttachment(attachment.id);
assert.ok(stub.calledOnce);
assert.ok(stub.calledWith(attachment));
stub.restore();
});
})