-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enables opening read-only files in electron. #9950
Enables opening read-only files in electron. #9950
Conversation
Signed-off-by: Kejsi Take <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good and I've tested that I can open a read-only file on Windows. There is a lot of weird behaviour around reading/writing files into read-only directories on Windows, but the PR fixes the particular problem the issue is about.
@colin-grant-work could you test on Linux? |
for (const uri of Array.isArray(uris) ? uris : [uris]) { | ||
if (!(await this.fileService.access(uri, FileAccess.Constants.R_OK))) { | ||
this.messageService.error(`Cannot read resource at ${uri.path}.`); | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could imagine that this could impact performance for large arrays of URIs because every access
call is sequential. We can parallelize this fairly well like this:
for (const uri of Array.isArray(uris) ? uris : [uris]) { | |
if (!(await this.fileService.access(uri, FileAccess.Constants.R_OK))) { | |
this.messageService.error(`Cannot read resource at ${uri.path}.`); | |
return false; | |
} | |
} | |
const filePaths = await Promise.all((Array.isArray(uris) ? uris : [uris]).map(uri => { | |
return !await this.fileService.access(uri, FileAccess.Constants.R_OK) && uri.path || ''; | |
}).filter(e => e); | |
if (filePaths.length) { | |
this.messageService.error(`Cannot read ${filePaths.length} resources: ${filePaths.join(', ')}`); | |
} | |
return !!filePaths.length; |
Hi @kejsitake, thank you for your first contribution and taking care of this issue 👍 Please be sure to sign the eclipse contributor agreement (eca) with the same email as your authorship in order for us to accept the changes. |
Signed-off-by: Kejsi Take [email protected]
I think I got the changes done and signed the eca. I am happy to look at this again if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me and works. One minor comment about naming that may prevent future confusion, but otherwise 👍
packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts
Outdated
Show resolved
Hide resolved
…cannot be opened Signed-off-by: Kejsi Take [email protected]
packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Kejsi Take [email protected]
@kejsitake Thank you very much for the contribution! |
packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts
Outdated
Show resolved
Hide resolved
packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-service.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Kejsi Take [email protected]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me as well 👍
Signed-off-by: Kejsi Take <[email protected]>
Signed-off-by: Kejsi Take <[email protected]>
Signed-off-by: Kejsi Take [email protected]
Fixes: #9860
Makes sure that a user can open a new file in the ElectronFileDialog when it has Read permissions (and not Write).
What it does
How to test
After making the above-mentioned changes, I ran the Electron example and verified that I could open a file that had only read permissions.
Review checklist