Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addDirectory(directory: Directory) {
const path = directory.getPath();
const parentDirPath = FileUtils.getDirPath(path);
const isRootDir = parentDirPath === path;
// remove any orphans that have a loaded parent
for (const orphanDir of this.orphanDirs.getValues()) {
const orphanDirPath = orphanDir.getPath();
const orphanDirParentPath = FileUtils.getDirPath(orphanDirPath);
const isOrphanRootDir = orphanDirParentPath === orphanDirPath;
if (!isOrphanRootDir && orphanDirParentPath === path)
this.orphanDirs.removeByKey(orphanDirPath);
}
if (!isRootDir)
this.addToDirectoriesByDirPath(directory);
if (!this.has(parentDirPath))
this.orphanDirs.set(path, directory);
addDirectory(directory: Directory) {
const path = directory.getPath();
const parentDirPath = FileUtils.getDirPath(path);
const isRootDir = parentDirPath === path;
// remove any orphans that have a loaded parent
for (const orphanDir of this.orphanDirs.getValues()) {
const orphanDirPath = orphanDir.getPath();
const orphanDirParentPath = FileUtils.getDirPath(orphanDirPath);
const isOrphanRootDir = orphanDirParentPath === orphanDirPath;
if (!isOrphanRootDir && orphanDirParentPath === path)
this.orphanDirs.removeByKey(orphanDirPath);
}
if (!isRootDir)
this.addToDirectoriesByDirPath(directory);
if (!this.has(parentDirPath))
this.orphanDirs.set(path, directory);
this.directoriesByPath.set(path, directory);
if (!this.context.fileSystemWrapper.directoryExistsSync(path))
this.context.fileSystemWrapper.queueMkdir(path);
for (const orphanDir of this.orphanDirs.getValues()) {
private removeFromDirectoriesByDirPath(dirPath: string) {
if (FileUtils.isRootDirPath(dirPath))
return;
const parentDirPath = FileUtils.getDirPath(dirPath);
const directories = this.directoriesByDirPath.get(parentDirPath);
if (directories == null)
return;
directories.removeByKey(FileUtils.getBaseName(dirPath));
// clean up
if (!directories.hasItems())
this.directoriesByDirPath.removeByKey(parentDirPath);
}
private addToDirectoriesByDirPath(directory: Directory) {
if (FileUtils.isRootDirPath(directory.getPath()))
return;
const parentDirPath = FileUtils.getDirPath(directory.getPath());
const directories = this.directoriesByDirPath.getOrCreate(parentDirPath,
() => new SortedKeyValueArray(item => item.getBaseName(), LocaleStringComparer.instance));
directories.set(directory);
}
function* getAncestorsUpToOneInProject(dir: Directory): IterableIterator {
if (FileUtils.isRootDirPath(dir.getPath()))
return;
const parentDirPath = FileUtils.getDirPath(dir.getPath());
const parentDir = compilerFactory.getDirectoryFromCacheOnlyIfInCache(parentDirPath);
if (parentDir == null)
return;
yield parentDir;
if (!inProjectCoordinator.isDirectoryInProject(parentDir))
yield* getAncestorsUpToOneInProject(parentDir);
}
}
private fillParentsOfDirPath(dirPath: string) {
const passedDirPaths: string[] = [];
let parentDir = FileUtils.getDirPath(dirPath);
while (dirPath !== parentDir) {
dirPath = parentDir;
parentDir = FileUtils.getDirPath(dirPath);
if (this.directoriesByPath.has(dirPath)) {
for (const currentDirPath of passedDirPaths)
this.createDirectory(currentDirPath);
break;
}
passedDirPaths.unshift(dirPath);
}
}
}