Skip to content
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

Electron File Dialog Can't Open Read-only Files #9860

Closed
colin-grant-work opened this issue Aug 6, 2021 · 2 comments · Fixed by #9950
Closed

Electron File Dialog Can't Open Read-only Files #9860

colin-grant-work opened this issue Aug 6, 2021 · 2 comments · Fixed by #9950
Labels
electron issues related to the electron target file dialog issues related to the file dialog good first issue good first issues for new contributors help wanted issues meant to be picked up, require help

Comments

@colin-grant-work
Copy link
Contributor

Bug Description:

Before returning from .showOpenDialog(), the ElectronFileDialogService checks whether the selected files are both readable and writable for the current user. It seems the check for writability makes sense for the .showSaveDialog() method, but not necessarily for the .showOpenDialog() case, since 'opening' doesn't necessarily imply writing.

async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<MaybeArray<URI> | undefined> {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
const { filePaths } = await remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props));
if (filePaths.length === 0) {
return undefined;
}
const uris = filePaths.map(path => FileUri.create(path));
const canAccess = await this.canReadWrite(uris);
const result = canAccess ? uris.length === 1 ? uris[0] : uris : undefined;
return result;
}
return undefined;
}

protected async canReadWrite(uris: MaybeArray<URI>): Promise<boolean> {
for (const uri of Array.isArray(uris) ? uris : [uris]) {
if (!(await this.fileService.access(uri, FileAccess.Constants.R_OK | FileAccess.Constants.W_OK))) {
this.messageService.error(`Cannot access resource at ${uri.path}.`);
return false;
}
}
return true;
}

Steps to Reproduce:

  1. On a multi-user system, find or create a file that certain users can read but not write
  2. As a user who can read but not write to a given file, try to 'open' the file using the file dialog
  3. See an error toast Cannot access resource at <path>.
  • Operating System: RHEL7
  • Theia Version: 7e09e93
@colin-grant-work colin-grant-work added electron issues related to the electron target file dialog issues related to the file dialog labels Aug 6, 2021
@tsmaeder tsmaeder added help wanted issues meant to be picked up, require help good first issue good first issues for new contributors labels Aug 20, 2021
@tsmaeder
Copy link
Contributor

Sounds like a low hanging fruit for a new contributor.

@kejsitake
Copy link
Contributor

Hi! I submitted a PR. I would be happy to make any other changes if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron issues related to the electron target file dialog issues related to the file dialog good first issue good first issues for new contributors help wanted issues meant to be picked up, require help
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants