Repository navigation
Fix the return value for FileSystem.isReadOnly(). #9800
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,7 @@ import { injectable } from 'inversify'; | |
| import { promisify } from 'util'; | ||
| import * as vscode from 'vscode'; | ||
| import { createDeferred } from '../utils/async'; | ||
| import { noop } from '../utils/misc'; | ||
| import { isFileNotFoundError } from './errors'; | ||
| import { isFileNotFoundError, isNoPermissionsError } from './errors'; | ||
| import { FileSystemPaths, FileSystemPathUtils } from './fs-paths'; | ||
| import { TemporaryFileSystem } from './fs-temp'; | ||
| // prettier-ignore | ||
|
|
@@ -457,16 +456,19 @@ export class FileSystem implements IFileSystem { | |
|
|
||
| public async isDirReadonly(dirname: string): Promise<boolean> { | ||
| const filePath = `${dirname}${this.paths.sep}___vscpTest___`; | ||
| return new Promise<boolean>(resolve => { | ||
| fs.open(filePath, fs.constants.O_CREAT | fs.constants.O_RDWR, (error, fd) => { | ||
| if (!error) { | ||
| fs.close(fd, () => { | ||
| fs.unlink(filePath, noop); | ||
| }); | ||
| } | ||
| return resolve(!error); | ||
| }); | ||
| }); | ||
| const flags = fs.constants.O_CREAT | fs.constants.O_RDWR; | ||
| let fd: number; | ||
| try { | ||
| fd = await fs.open(filePath, flags); | ||
| } catch (err) { | ||
| if (isNoPermissionsError(err)) { | ||
| return true; | ||
| } | ||
| throw err; // re-throw | ||
| } | ||
| await fs.close(fd); | ||
| await fs.unlink(filePath); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two could probably, be done in the back ground rather than awaiting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eric Snow (@ericsnowcurrently) Do you think it would be good to create a seprate PR to clean up the resources in the background, as opposed to awaiting on them and slowing the exit from this fn? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can submit one if you think its ok.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be great. Thanks! |
||
| 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.
Tests for this?