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

Enable FileSystemProvider to stat a file as readonly #73122

Closed
gjsjohnmurray opened this issue May 1, 2019 · 31 comments · Fixed by #111237
Closed

Enable FileSystemProvider to stat a file as readonly #73122

gjsjohnmurray opened this issue May 1, 2019 · 31 comments · Fixed by #111237
Assignees
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes remote Remote system operations issues verification-needed Verification of issue is requested verified Verification succeeded

Comments

@gjsjohnmurray
Copy link
Contributor

Currently a FileSystemProvider can register as readonly, meaning that every file it provides is opened in a readonly editor. This is nice, but even better if the FileStat it returns from its stat() method had an optional readonly property. Then I think this line could easily treat a true readonly value as a signal to set isReadonly true. @bpasero what do you think?

@bpasero
Copy link
Member

bpasero commented May 1, 2019

I think this is generally a nice idea, but I am worried that it will make file operations very complicated: imagine a folder where just a few files are readonly. Now a fs operation runs that operates on all files in the folder, not just one (e.g. rename of the folder? delete?). Naturally with this we would first have to ask the provider if any of the files that are potentially modified are readonly before even starting the operation, which seems quite crazy to me.

@gjsjohnmurray
Copy link
Contributor Author

Fair point, but what happens at the moment in such scenarios if the user has set restrictive OS-level file permissions to protect just a few of the files in a folder tree? Does VSCode already run a preflight check on, say, a parent folder delete and decline to start the operation if any of the descendant files isn't deletable?

@bpasero
Copy link
Member

bpasero commented May 1, 2019

@gjsjohnmurray yeah we are not doing anything but rely fully on the OS to do the right thing. If one file in a folder is write protected, the OS may decide that a rename on the parent folder is not possible (have not validated that).

@gjsjohnmurray
Copy link
Contributor Author

@bpasero I'd also argue that it shouldn't be VSCode's responsibility to recursively check the readonly stat of every file within a folder before asking the FileSystemProvider to delete the folder. The FSP is best placed to know if that's an appropriate check to make. For example my FSP might simply fail the folder delete request immediately because it's a root folder. I certainly don't want you to have wasted time (yours and mine) walking the entire tree and asking me to stat each file for you if I'm always going to reject your subsequent request to delete the root folder.

@bpasero
Copy link
Member

bpasero commented May 2, 2019

@gjsjohnmurray yeah good point 👍

@gjsjohnmurray
Copy link
Contributor Author

Please can this issue get some love soon?

@gjsjohnmurray
Copy link
Contributor Author

@jrieken are you open for a PR to implement this? I'm guessing it needs to be treated as proposed API. I'd copy the FileStat interface into vscode.proposed.d.ts, add readonly?: boolean, and wire this up. That has become a bit more complicated since @bpasero did some restructuring in 920d80e but ultimately the new readonly from FileStat would have its effect here.

return this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);

@jrieken
Copy link
Member

jrieken commented Nov 16, 2020

Proposing API is usually the very last step and requires an "internal" API first and I don't think there is one. I believe that would be around here and than needs options for editors, custom editor etc

@gjsjohnmurray
Copy link
Contributor Author

I have submitted draft PR #111237 for comment and guidance.

@bpasero
Copy link
Member

bpasero commented Nov 25, 2020

One thing to note is that if we decide to push this, the experience for readonly files will be different from how we treat OS readonly files. We would probably not adopt this for OS local files to preserve this current imho inferior behaviour:

  • you can always type in readonly files, even if they are readonly
  • you can save readonly files and be asked to overwrite the write protection at that point
  • you can still decide to "Save As" to a different file name to avoid readonly'ess

With this solution all you see is a readonly editor.

@bpasero
Copy link
Member

bpasero commented Mar 12, 2021

Little update to #73122 (comment): with 5a8936a there is a new notion of FileWriteLock errors that a provider can throw and a new unlock write capability. As such, the feature of unlocking write protected files is fully independent from "readonly" notion. As such I think it would be possible to allow for readonly files that turn the editor readonly without impacting the scenario of write protected files.

Timing wise I cannot make any better promises than tackling this in our issue grooming iteration.

@bpasero bpasero modified the milestones: Backlog, On Deck Jun 1, 2021
@gjsjohnmurray
Copy link
Contributor Author

I think this shipped in 1.57 so can be closed, right?

https://code.visualstudio.com/updates/v1_57#_enable-file-system-providers-to-declare-a-file-as-readonly

@bpasero
Copy link
Member

bpasero commented Jun 14, 2021

@gjsjohnmurray it is only proposed API, not finalized yet.

@gjsjohnmurray
Copy link
Contributor Author

@bpasero sorry, I misread the 1.57 release notes. I often find I miss the point where the "Proposed Extension APIs" section begins. Maybe the text of each subsection of that could helpfully reiterate "proposed API" in future release notes?

@bpasero
Copy link
Member

bpasero commented Sep 24, 2021

Verification

Test that you can mark a file as readonly without enabling proposed API via the permissions property on a file. #124846 has details how to use it.

@gjsjohnmurray if you are able to verify in current insiders, that would be ideal 👍

@DavyLandman
Copy link

I hope this isn't considered an annoying question, but what is the process for an api change like this to graduate out of the insiders/proposed status?

@bpasero
Copy link
Member

bpasero commented Sep 28, 2021

@DavyLandman
Copy link

@bpasero thanks, I was already clicking through the wiki, but seemed to have missed that.

So without jumping on calls, is there a way I can help move this forward? The change seems quite minimal, and would help 2 extensions I'm developing (both are languages with their own virtual file systems for some parts).

I saw this list, in the wiki:

  • Is there a non-trivial usage-sample for this new API?
  • Are there multiple (ideally not similar) use-cases that this proposal solves?
  • Is the proposal too narrow (not solving enough) or too broad (trying to solve too much)?
  • Who would use this new API?

And I'm not completely sure where this should be discussed? Should I raise a new issue, there are already quite a few issues about this topic on file specific read-only status.

@bpasero
Copy link
Member

bpasero commented Sep 28, 2021

@DavyLandman this API will be available in our upcoming release next week.

@DavyLandman
Copy link

Thanks @bpasero!

@lramos15 lramos15 added the author-verification-requested Issues potentially verifiable by issue author label Sep 28, 2021
@rchiodo rchiodo assigned bpasero, jrieken and rchiodo and unassigned bpasero and jrieken Sep 28, 2021
@rchiodo rchiodo added the verified Verification succeeded label Sep 28, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Sep 28, 2021

I believe this was verified by #124846?

@rchiodo rchiodo removed their assignment Sep 28, 2021
@gjsjohnmurray
Copy link
Contributor Author

@gjsjohnmurray if you are able to verify in current insiders, that would be ideal 👍

/verified

First I had to work out how to make fsprovider-sample use the new API because it is no longer in vscode.proposed.d.ts but not yet published in @types/vscode

@bpasero bpasero added the on-release-notes Issue/pull request mentioned in release notes label Sep 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes remote Remote system operations issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@DavyLandman @bpasero @jrieken @lramos15 @gjsjohnmurray @rchiodo and others