vscode.workspace.fs.readDirectory() ignores broken symlinks. (fix #90031)

This commit is contained in:
Benjamin Pasero 2020-02-05 11:41:46 +01:00
parent 7ed9930136
commit c739b34b50
2 changed files with 20 additions and 3 deletions

View file

@ -98,7 +98,18 @@ export class DiskFileSystemProvider extends Disposable implements
try {
let type: FileType;
if (child.isSymbolicLink()) {
type = (await this.stat(joinPath(resource, child.name))).type; // always resolve target the link points to if any
try {
type = (await this.stat(joinPath(resource, child.name))).type; // always resolve target the link points to if any
} catch (error) {
if (error.code !== FileSystemProviderErrorCode.FileNotFound) {
throw error; // any error that is not file not found is unexpected
}
// a symbolic link can point to a target that does
// not exist on the file system. in that case we
// still want to return the element as UNKNOWN.
type = FileType.SymbolicLink | FileType.Unknown;
}
} else {
type = this.toType(child);
}

View file

@ -440,7 +440,7 @@ suite('Disk File Service', function () {
assert.equal(resolved.isSymbolicLink, true);
});
test('resolve - invalid symbolic link does not break', async () => {
test('resolve - symbolic link pointing to non-existing file does not break', async () => {
if (isWindows) {
return; // not reliable on windows
}
@ -450,7 +450,13 @@ suite('Disk File Service', function () {
const resolved = await service.resolve(URI.file(testDir));
assert.equal(resolved.isDirectory, true);
assert.equal(resolved.children!.length, 8);
assert.equal(resolved.children!.length, 9);
const resolvedLink = resolved.children?.filter(child => child.name === 'bar' && child.isSymbolicLink)[0];
assert.ok(resolvedLink);
assert.ok(!resolvedLink?.isDirectory);
assert.ok(!resolvedLink?.isFile);
});
test('deleteFile', async () => {