Skip to content

Commit 444567f

Browse files
author
Benjamin Pasero
committed
files - skip exists() check if not needed
1 parent 672ca38 commit 444567f

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/vs/platform/files/node/diskFileSystemProvider.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,18 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
126126
try {
127127
const filePath = this.toFilePath(resource);
128128

129-
// Validate target
130-
const fileExists = await exists(filePath);
131-
if (fileExists && !opts.overwrite) {
132-
throw createFileSystemProviderError(new Error(localize('fileExists', "File already exists")), FileSystemProviderErrorCode.FileExists);
133-
} else if (!fileExists && !opts.create) {
134-
throw createFileSystemProviderError(new Error(localize('fileNotExists', "File does not exist")), FileSystemProviderErrorCode.FileNotFound);
129+
// Validate target unless { create: true, overwrite: true }
130+
if (!opts.create || !opts.overwrite) {
131+
const fileExists = await exists(filePath);
132+
if (fileExists) {
133+
if (!opts.overwrite) {
134+
throw createFileSystemProviderError(new Error(localize('fileExists', "File already exists")), FileSystemProviderErrorCode.FileExists);
135+
}
136+
} else {
137+
if (!opts.create) {
138+
throw createFileSystemProviderError(new Error(localize('fileNotExists', "File does not exist")), FileSystemProviderErrorCode.FileNotFound);
139+
}
140+
}
135141
}
136142

137143
// Open

0 commit comments

Comments
 (0)