| 108 | |
| 109 | // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging |
| 110 | export class HostTree implements Tree { |
| 111 | private readonly _id = --_uniqueId; |
| 112 | private _record: virtualFs.CordHost; |
| 113 | private _recordSync: virtualFs.SyncDelegateHost; |
| 114 | private _ancestry = new Set<number>(); |
| 115 | |
| 116 | private _dirCache = new Map<Path, HostDirEntry>(); |
| 117 | |
| 118 | static isHostTree(tree: Tree): tree is HostTree { |
| 119 | if (tree instanceof HostTree) { |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | if (typeof tree === 'object' && typeof (tree as HostTree)._ancestry === 'object') { |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | constructor(protected _backend: virtualFs.ReadonlyHost<{}> = new virtualFs.Empty()) { |
| 131 | this[TreeSymbol] = () => this; |
| 132 | this._record = new virtualFs.CordHost(new virtualFs.SafeReadonlyHost(_backend)); |
| 133 | this._recordSync = new virtualFs.SyncDelegateHost(this._record); |
| 134 | } |
| 135 | |
| 136 | protected _normalizePath(path: string): Path { |
| 137 | return normalize('/' + path); |
| 138 | } |
| 139 | |
| 140 | protected _willCreate(path: Path): boolean { |
| 141 | return this._record.willCreate(path); |
| 142 | } |
| 143 | |
| 144 | protected _willOverwrite(path: Path): boolean { |
| 145 | return this._record.willOverwrite(path); |
| 146 | } |
| 147 | |
| 148 | protected _willDelete(path: Path): boolean { |
| 149 | return this._record.willDelete(path); |
| 150 | } |
| 151 | |
| 152 | protected _willRename(path: Path): boolean { |
| 153 | return this._record.willRename(path); |
| 154 | } |
| 155 | |
| 156 | branch(): Tree { |
| 157 | const branchedTree = new HostTree(this._backend); |
| 158 | branchedTree._record = this._record.clone(); |
| 159 | branchedTree._recordSync = new virtualFs.SyncDelegateHost(branchedTree._record); |
| 160 | branchedTree._ancestry = new Set(this._ancestry).add(this._id); |
| 161 | |
| 162 | return branchedTree; |
| 163 | } |
| 164 | |
| 165 | private isAncestorOf(tree: Tree): boolean { |
| 166 | if (tree instanceof HostTree) { |
| 167 | return tree._ancestry.has(this._id); |
nothing calls this directly
no outgoing calls
no test coverage detected