Git - add error handling for traversing workspace folders during repository discovery (#213975)

This commit is contained in:
Ladislau Szomoru 2024-05-31 11:24:12 +02:00 committed by GitHub
parent fab42a71ba
commit cf3e34fc2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -379,15 +379,26 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
while (foldersToTravers.length > 0) {
const currentFolder = foldersToTravers.shift()!;
const children: fs.Dirent[] = [];
try {
children.push(...await fs.promises.readdir(currentFolder.path, { withFileTypes: true }));
if (currentFolder.depth !== 0) {
result.push(currentFolder.path);
}
}
catch (err) {
this.logger.warn(`[swsf] Unable to read folder '${currentFolder.path}': ${err}`);
continue;
}
if (currentFolder.depth < maxDepth || maxDepth === -1) {
const children = await fs.promises.readdir(currentFolder.path, { withFileTypes: true });
const childrenFolders = children
.filter(dirent =>
dirent.isDirectory() && dirent.name !== '.git' &&
!repositoryScanIgnoredFolders.find(f => pathEquals(dirent.name, f)))
.map(dirent => path.join(currentFolder.path, dirent.name));
result.push(...childrenFolders);
foldersToTravers.push(...childrenFolders.map(folder => {
return { path: folder, depth: currentFolder.depth + 1 };
}));