mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
validate extension-given file system provider (#175357)
fixes https://github.com/microsoft/vscode/issues/173502
This commit is contained in:
parent
02fa5bc980
commit
756ef3ff47
|
@ -128,9 +128,11 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
|
|||
this._linkProviderRegistration?.dispose();
|
||||
}
|
||||
|
||||
|
||||
registerFileSystemProvider(extension: IExtensionDescription, scheme: string, provider: vscode.FileSystemProvider, options: { isCaseSensitive?: boolean; isReadonly?: boolean } = {}) {
|
||||
|
||||
// validate the given provider is complete
|
||||
ExtHostFileSystem._validateFileSystemProvider(provider);
|
||||
|
||||
if (this._registeredSchemes.has(scheme)) {
|
||||
throw new Error(`a provider for the scheme '${scheme}' is already registered`);
|
||||
}
|
||||
|
@ -203,6 +205,36 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
|
|||
});
|
||||
}
|
||||
|
||||
private static _validateFileSystemProvider(provider: vscode.FileSystemProvider) {
|
||||
if (!provider) {
|
||||
throw new Error('MISSING provider');
|
||||
}
|
||||
if (typeof provider.watch !== 'function') {
|
||||
throw new Error('Provider does NOT implement watch');
|
||||
}
|
||||
if (typeof provider.stat !== 'function') {
|
||||
throw new Error('Provider does NOT implement stat');
|
||||
}
|
||||
if (typeof provider.readDirectory !== 'function') {
|
||||
throw new Error('Provider does NOT implement readDirectory');
|
||||
}
|
||||
if (typeof provider.createDirectory !== 'function') {
|
||||
throw new Error('Provider does NOT implement createDirectory');
|
||||
}
|
||||
if (typeof provider.readFile !== 'function') {
|
||||
throw new Error('Provider does NOT implement readFile');
|
||||
}
|
||||
if (typeof provider.writeFile !== 'function') {
|
||||
throw new Error('Provider does NOT implement writeFile');
|
||||
}
|
||||
if (typeof provider.delete !== 'function') {
|
||||
throw new Error('Provider does NOT implement delete');
|
||||
}
|
||||
if (typeof provider.rename !== 'function') {
|
||||
throw new Error('Provider does NOT implement rename');
|
||||
}
|
||||
}
|
||||
|
||||
private static _asIStat(stat: vscode.FileStat): files.IStat {
|
||||
const { type, ctime, mtime, size, permissions } = stat;
|
||||
return { type, ctime, mtime, size, permissions };
|
||||
|
|
Loading…
Reference in a new issue