Skip to content

Commit 001615e

Browse files
committed
No need for additional readonly and missing file check.
1 parent 0daeaf5 commit 001615e

File tree

1 file changed

+2
-70
lines changed

1 file changed

+2
-70
lines changed

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
328328
}
329329

330330
// validate write
331-
const statBeforeWrite = await this._validateWriteFile(uri, options);
332-
333-
if (!statBeforeWrite) {
334-
await this._mkdirp(uri);
335-
}
331+
await this._validateWriteFile(uri, options);
336332

337333
const data: vscode.NotebookData = {
338334
metadata: filter(document.apiNotebook.metadata, key => !(serializer.options?.transientDocumentMetadata ?? {})[key]),
@@ -377,20 +373,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
377373
}
378374

379375
private async _validateWriteFile(uri: URI, options: files.IWriteFileOptions) {
380-
// File system provider registered in Extension Host doesn't have unlock or atomic support
381-
// Validate via file stat meta data
382376
const stat = await this._extHostFileSystem.value.stat(uri);
383-
384-
// File cannot be directory
385-
if ((stat.type & files.FileType.Directory) !== 0) {
386-
throw new files.FileOperationError(localize('fileIsDirectoryWriteError', "Unable to write file '{0}' that is actually a directory", this._resourceForError(uri)), files.FileOperationResult.FILE_IS_DIRECTORY, options);
387-
}
388-
389-
// File cannot be readonly
390-
if ((stat.permissions ?? 0) & files.FilePermission.Readonly) {
391-
throw new files.FileOperationError(localize('err.readonly', "Unable to modify read-only file '{0}'", this._resourceForError(uri)), files.FileOperationResult.FILE_PERMISSION_DENIED);
392-
}
393-
394377
// Dirty write prevention
395378
if (
396379
typeof options?.mtime === 'number' && typeof options.etag === 'string' && options.etag !== files.ETAG_DISABLED &&
@@ -400,58 +383,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
400383
throw new files.FileOperationError(localize('fileModifiedError', "File Modified Since"), files.FileOperationResult.FILE_MODIFIED_SINCE, options);
401384
}
402385

403-
return stat;
404-
}
405-
406-
private async _mkdirp(uri: URI) {
407-
const providerExtUri = this._extHostFileSystem.getFileSystemProviderExtUri(uri.scheme);
408-
let directory = providerExtUri.dirname(uri);
409-
410-
const directoriesToCreate: string[] = [];
411-
412-
while (!providerExtUri.isEqual(directory, providerExtUri.dirname(directory))) {
413-
try {
414-
const stat = await this._extHostFileSystem.value.stat(directory);
415-
if ((stat.type & files.FileType.Directory) === 0) {
416-
throw new Error(localize('mkdirExistsError', "Unable to create folder '{0}' that already exists but is not a directory", this._resourceForError(directory)));
417-
}
418-
419-
break; // we have hit a directory that exists -> good
420-
} catch (error) {
421-
422-
// Bubble up any other error that is not file not found
423-
if (files.toFileSystemProviderErrorCode(error) !== files.FileSystemProviderErrorCode.FileNotFound) {
424-
throw error;
425-
}
426-
427-
// Upon error, remember directories that need to be created
428-
directoriesToCreate.push(providerExtUri.basename(directory));
429-
430-
// Continue up
431-
directory = providerExtUri.dirname(directory);
432-
}
433-
}
434-
435-
// Create directories as needed
436-
for (let i = directoriesToCreate.length - 1; i >= 0; i--) {
437-
directory = providerExtUri.joinPath(directory, directoriesToCreate[i]);
438-
439-
try {
440-
await this._extHostFileSystem.value.createDirectory(directory);
441-
} catch (error) {
442-
if (files.toFileSystemProviderErrorCode(error) !== files.FileSystemProviderErrorCode.FileExists) {
443-
// For mkdirp() we tolerate that the mkdir() call fails
444-
// in case the folder already exists. This follows node.js
445-
// own implementation of fs.mkdir({ recursive: true }) and
446-
// reduces the chances of race conditions leading to errors
447-
// if multiple calls try to create the same folders
448-
// As such, we only throw an error here if it is other than
449-
// the fact that the file already exists.
450-
// (see also https://github.com/microsoft/vscode/issues/89834)
451-
throw error;
452-
}
453-
}
454-
}
386+
return;
455387
}
456388

457389
private _resourceForError(uri: URI): string {

0 commit comments

Comments
 (0)