提交 f0b65367 编写于 作者: B Benjamin Pasero

remove hasChildren for #41497

上级 ec91297c
......@@ -409,12 +409,6 @@ export interface IFileStat extends IBaseStat {
*/
isDirectory: boolean;
/**
* Return {{true}} when this is a directory
* that is not empty.
*/
hasChildren: boolean;
/**
* The children of the file stat or undefined if none.
*/
......
......@@ -38,7 +38,7 @@ export class OpenExtensionsFolderAction extends Action {
return this.fileService.resolveFile(URI.file(extensionsHome)).then(file => {
let itemToShow: string;
if (file.hasChildren) {
if (file.children && file.children.length > 0) {
itemToShow = file.children[0].resource.fsPath;
} else {
itemToShow = paths.normalize(extensionsHome, true);
......
......@@ -73,17 +73,15 @@ export class FileStat implements IFileStat {
public mtime: number;
public etag: string;
private _isDirectory: boolean;
public hasChildren: boolean;
public children: FileStat[];
public parent: FileStat;
public isDirectoryResolved: boolean;
constructor(resource: URI, public root: FileStat, isDirectory?: boolean, hasChildren?: boolean, name: string = getPathLabel(resource), mtime?: number, etag?: string) {
constructor(resource: URI, public root: FileStat, isDirectory?: boolean, name: string = getPathLabel(resource), mtime?: number, etag?: string) {
this.resource = resource;
this.name = name;
this.isDirectory = !!isDirectory;
this.hasChildren = isDirectory && hasChildren;
this.etag = etag;
this.mtime = mtime;
......@@ -123,7 +121,7 @@ export class FileStat implements IFileStat {
}
public static create(raw: IFileStat, root: FileStat, resolveTo?: URI[]): FileStat {
const stat = new FileStat(raw.resource, root, raw.isDirectory, raw.hasChildren, raw.name, raw.mtime, raw.etag);
const stat = new FileStat(raw.resource, root, raw.isDirectory, raw.name, raw.mtime, raw.etag);
// Recursively add children if present
if (stat.isDirectory) {
......@@ -141,7 +139,6 @@ export class FileStat implements IFileStat {
const child = FileStat.create(raw.children[i], root, resolveTo);
child.parent = stat;
stat.children.push(child);
stat.hasChildren = stat.children.length > 0;
}
}
}
......@@ -169,7 +166,6 @@ export class FileStat implements IFileStat {
local.resource = disk.resource;
local.name = disk.name;
local.isDirectory = disk.isDirectory;
local.hasChildren = disk.isDirectory && disk.hasChildren;
local.mtime = disk.mtime;
local.isDirectoryResolved = disk.isDirectoryResolved;
......@@ -217,7 +213,6 @@ export class FileStat implements IFileStat {
child.updateResource(false);
this.children.push(child);
this.hasChildren = this.children.length > 0;
}
/**
......@@ -230,8 +225,6 @@ export class FileStat implements IFileStat {
break;
}
}
this.hasChildren = this.children.length > 0;
}
/**
......@@ -256,10 +249,9 @@ export class FileStat implements IFileStat {
private updateResource(recursive: boolean): void {
this.resource = this.parent.resource.with({ path: paths.join(this.parent.resource.path, this.name) });
// this.resource = URI.file(paths.join(this.parent.resource.fsPath, this.name));
if (recursive) {
if (this.isDirectory && this.hasChildren && this.children) {
if (this.isDirectory && this.children) {
this.children.forEach((child: FileStat) => {
child.updateResource(true);
});
......@@ -293,7 +285,7 @@ export class FileStat implements IFileStat {
}
// Return if not having any children
if (!this.hasChildren) {
if (!this.children) {
return null;
}
......@@ -322,7 +314,7 @@ export class NewStatPlaceholder extends FileStat {
private directoryPlaceholder: boolean;
constructor(isDirectory: boolean, root: FileStat) {
super(URI.file(''), root, false, false, '');
super(URI.file(''), root, false, '');
this.id = NewStatPlaceholder.ID++;
this.isDirectoryResolved = isDirectory;
......@@ -335,7 +327,6 @@ export class NewStatPlaceholder extends FileStat {
this.isDirectoryResolved = void 0;
this.name = void 0;
this.isDirectory = void 0;
this.hasChildren = void 0;
this.mtime = void 0;
}
......@@ -374,8 +365,6 @@ export class NewStatPlaceholder extends FileStat {
child.parent = parent;
parent.children.push(child);
parent.hasChildren = parent.children.length > 0;
return child;
}
}
......
......@@ -787,8 +787,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
name: paths.basename(resource.fsPath),
mtime: 0,
etag: undefined,
isDirectory: true,
hasChildren: false
isDirectory: true
}, root);
if (targetsToResolve.every(t => t.root.resource.scheme === 'file')) {
......
......@@ -104,7 +104,6 @@ export class FileDataSource implements IDataSource {
return stat.children;
}, (e: any) => {
stat.hasChildren = false;
this.messageService.show(Severity.Error, e);
return []; // we could not resolve any children because of an error
......
......@@ -14,7 +14,7 @@ import { validateFileName } from 'vs/workbench/parts/files/electron-browser/file
import { FileStat } from 'vs/workbench/parts/files/common/explorerModel';
function createStat(path: string, name: string, isFolder: boolean, hasChildren: boolean, size: number, mtime: number): FileStat {
return new FileStat(toResource(path), undefined, isFolder, hasChildren, name, mtime);
return new FileStat(toResource(path), undefined, isFolder, name, mtime);
}
function toResource(path) {
......@@ -31,7 +31,6 @@ suite('Files - View Model', () => {
assert.strictEqual(s.resource.fsPath, toResource('/path/to/stat').fsPath);
assert.strictEqual(s.name, 'sName');
assert.strictEqual(s.isDirectory, true);
assert.strictEqual(s.hasChildren, true);
assert.strictEqual(s.mtime, new Date(d).getTime());
assert(isArray(s.children) && s.children.length === 0);
......@@ -49,14 +48,12 @@ suite('Files - View Model', () => {
s.addChild(child1);
assert(s.children.length === 1);
assert(s.hasChildren);
s.removeChild(child1);
s.addChild(child1);
assert(s.children.length === 1);
s.removeChild(child1);
assert(!s.hasChildren);
assert(s.children.length === 0);
// Assert that adding a child updates its path properly
......@@ -79,7 +76,6 @@ suite('Files - View Model', () => {
s4.move(s1);
assert.strictEqual(s3.children.length, 0);
assert.strictEqual(s3.hasChildren, false);
assert.strictEqual(s1.children.length, 2);
......@@ -239,20 +235,20 @@ suite('Files - View Model', () => {
test('Merge Local with Disk', function () {
const d = new Date().toUTCString();
const merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), undefined, true, false, 'to', Date.now(), d);
const merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), undefined, true, false, 'to', Date.now(), new Date(0).toUTCString());
const merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), undefined, true, 'to', Date.now(), d);
const merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), undefined, true, 'to', Date.now(), new Date(0).toUTCString());
// Merge Properties
FileStat.mergeLocalWithDisk(merge2, merge1);
assert.strictEqual(merge1.mtime, merge2.mtime);
// Merge Child when isDirectoryResolved=false is a no-op
merge2.addChild(new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), undefined, true, false, 'foo.html', Date.now(), d));
merge2.addChild(new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), undefined, true, 'foo.html', Date.now(), d));
FileStat.mergeLocalWithDisk(merge2, merge1);
assert.strictEqual(merge1.children.length, 0);
// Merge Child with isDirectoryResolved=true
const child = new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), undefined, true, false, 'foo.html', Date.now(), d);
const child = new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), undefined, true, 'foo.html', Date.now(), d);
merge2.removeChild(child);
merge2.addChild(child);
merge2.isDirectoryResolved = true;
......
......@@ -31,7 +31,6 @@ function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse
const [resource, stat] = tuple;
const fileStat: IFileStat = {
isDirectory: false,
hasChildren: false,
resource: resource,
name: basename(resource.path),
mtime: stat.mtime,
......@@ -41,13 +40,11 @@ function toIFileStat(provider: IFileSystemProvider, tuple: [URI, IStat], recurse
if (stat.type === FileType.Dir) {
fileStat.isDirectory = true;
fileStat.hasChildren = true;
if (recurse && recurse([resource, stat])) {
// dir -> resolve
return provider.readdir(resource).then(entries => {
fileStat.isDirectory = true;
fileStat.hasChildren = entries.length > 0;
// resolve children if requested
return TPromise.join(entries.map(stat => toIFileStat(provider, stat, recurse))).then(children => {
......
......@@ -1132,7 +1132,6 @@ export class StatResolver {
const fileStat: IFileStat = {
resource: this.resource,
isDirectory: this.isDirectory,
hasChildren: undefined,
name: this.name,
etag: this.etag,
size: this.size,
......@@ -1161,7 +1160,6 @@ export class StatResolver {
// Load children
this.resolveChildren(this.resource.fsPath, absoluteTargetPaths, options && options.resolveSingleChildDescendants, children => {
children = arrays.coalesce(children); // we don't want those null children (could be permission denied when reading a child)
fileStat.hasChildren = children && children.length > 0;
fileStat.children = children || [];
c(fileStat);
......@@ -1215,7 +1213,6 @@ export class StatResolver {
const childStat: IFileStat = {
resource: fileResource,
isDirectory: fileStat.isDirectory(),
hasChildren: childCount > 0,
name: file,
mtime: fileStat.mtime.getTime(),
etag: etag(fileStat),
......@@ -1239,7 +1236,6 @@ export class StatResolver {
if (resolveFolderChildren) {
$this.resolveChildren(fileResource.fsPath, absoluteTargetPaths, resolveSingleChildDescendants, children => {
children = arrays.coalesce(children); // we don't want those null children
childStat.hasChildren = children && children.length > 0;
childStat.children = children || [];
clb(null, childStat);
......
......@@ -54,7 +54,7 @@ suite('Stat Resolver', () => {
resolver.resolve(null).then(result => {
assert.ok(result);
assert.ok(result.children);
assert.ok(result.hasChildren);
assert.ok(result.children.length > 0);
assert.ok(result.isDirectory);
assert.equal(result.children.length, testsElements.length);
......@@ -68,13 +68,12 @@ suite('Stat Resolver', () => {
assert.ok(path.basename(value.resource.fsPath));
if (['examples', 'other'].indexOf(path.basename(value.resource.fsPath)) >= 0) {
assert.ok(value.isDirectory);
assert.ok(value.hasChildren);
} else if (path.basename(value.resource.fsPath) === 'index.html') {
assert.ok(!value.isDirectory);
assert.ok(value.hasChildren === false);
assert.ok(!value.children);
} else if (path.basename(value.resource.fsPath) === 'site.css') {
assert.ok(!value.isDirectory);
assert.ok(value.hasChildren === false);
assert.ok(!value.children);
} else {
assert.ok(!'Unexpected value ' + path.basename(value.resource.fsPath));
}
......@@ -89,7 +88,7 @@ suite('Stat Resolver', () => {
resolver.resolve({ resolveTo: [toResource('other/deep')] }).then(result => {
assert.ok(result);
assert.ok(result.children);
assert.ok(result.hasChildren);
assert.ok(result.children.length > 0);
assert.ok(result.isDirectory);
let children = result.children;
......@@ -97,11 +96,11 @@ suite('Stat Resolver', () => {
let other = utils.getByName(result, 'other');
assert.ok(other);
assert.ok(other.hasChildren);
assert.ok(other.children.length > 0);
let deep = utils.getByName(other, 'deep');
assert.ok(deep);
assert.ok(deep.hasChildren);
assert.ok(deep.children.length > 0);
assert.equal(deep.children.length, 4);
})
.done(() => done(), done);
......@@ -113,7 +112,7 @@ suite('Stat Resolver', () => {
resolver.resolve({ resolveTo: [toResource('other/Deep')] }).then(result => {
assert.ok(result);
assert.ok(result.children);
assert.ok(result.hasChildren);
assert.ok(result.children.length > 0);
assert.ok(result.isDirectory);
let children = result.children;
......@@ -121,16 +120,16 @@ suite('Stat Resolver', () => {
let other = utils.getByName(result, 'other');
assert.ok(other);
assert.ok(other.hasChildren);
assert.ok(other.children.length > 0);
let deep = utils.getByName(other, 'deep');
if (isLinux) { // Linux has case sensitive file system
assert.ok(deep);
assert.ok(deep.hasChildren);
assert.ok(deep.children.length > 0);
assert.ok(!deep.children); // not resolved because we got instructed to resolve other/Deep with capital D
} else {
assert.ok(deep);
assert.ok(deep.hasChildren);
assert.ok(deep.children.length > 0);
assert.equal(deep.children.length, 4);
}
})
......@@ -143,7 +142,7 @@ suite('Stat Resolver', () => {
resolver.resolve({ resolveTo: [toResource('other/deep'), toResource('examples')] }).then(result => {
assert.ok(result);
assert.ok(result.children);
assert.ok(result.hasChildren);
assert.ok(result.children.length > 0);
assert.ok(result.isDirectory);
let children = result.children;
......@@ -151,16 +150,16 @@ suite('Stat Resolver', () => {
let other = utils.getByName(result, 'other');
assert.ok(other);
assert.ok(other.hasChildren);
assert.ok(other.children.length > 0);
let deep = utils.getByName(other, 'deep');
assert.ok(deep);
assert.ok(deep.hasChildren);
assert.ok(deep.children.length > 0);
assert.equal(deep.children.length, 4);
let examples = utils.getByName(result, 'examples');
assert.ok(examples);
assert.ok(examples.hasChildren);
assert.ok(examples.children.length > 0);
assert.equal(examples.children.length, 4);
})
.done(() => done(), done);
......@@ -172,7 +171,7 @@ suite('Stat Resolver', () => {
resolver.resolve({ resolveSingleChildDescendants: true }).then(result => {
assert.ok(result);
assert.ok(result.children);
assert.ok(result.hasChildren);
assert.ok(result.children.length > 0);
assert.ok(result.isDirectory);
let children = result.children;
......@@ -180,7 +179,7 @@ suite('Stat Resolver', () => {
let deep = utils.getByName(result, 'deep');
assert.ok(deep);
assert.ok(deep.hasChildren);
assert.ok(deep.children.length > 0);
assert.equal(deep.children.length, 4);
})
.done(() => done(), done);
......
......@@ -393,8 +393,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
mtime: content.mtime,
etag: content.etag,
isDirectory: false,
hasChildren: false,
children: void 0,
children: void 0
};
this.updateLastResolvedDiskStat(resolvedStat);
......
......@@ -711,7 +711,6 @@ export class TestFileService implements IFileService {
encoding: 'utf8',
mtime: Date.now(),
isDirectory: false,
hasChildren: false,
name: paths.basename(resource.fsPath)
});
}
......@@ -763,7 +762,6 @@ export class TestFileService implements IFileService {
encoding: 'utf8',
mtime: Date.now(),
isDirectory: false,
hasChildren: false,
name: paths.basename(resource.fsPath)
};
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册