Add guard before checking locally installed backends

This commit is contained in:
Akarshan 2025-09-08 13:08:14 +05:30
parent 4e37c361c4
commit a6e4f28830
No known key found for this signature in database
GPG Key ID: D75C9634A870665F

View File

@ -18,22 +18,24 @@ export async function getLocalInstalledBackends(): Promise<
'llamacpp',
'backends',
])
const versionDirs = await fs.readdirSync(backendsDir)
if (await fs.existsSync(backendsDir)) {
const versionDirs = await fs.readdirSync(backendsDir)
// If the folder does not exist we are done.
if (!versionDirs) {
return local
}
for (const version of versionDirs) {
const versionPath = await joinPath([backendsDir, version])
const versionName = await basename(versionPath)
const backendTypes = await fs.readdirSync(versionPath)
// If the folder does not exist we are done.
if (!versionDirs) {
return local
}
for (const version of versionDirs) {
const versionPath = await joinPath([backendsDir, version])
const versionName = await basename(versionPath)
const backendTypes = await fs.readdirSync(versionPath)
// Verify that the backend is really installed
for (const backendType of backendTypes) {
const backendName = await basename(backendType)
if (await isBackendInstalled(backendType, versionName)) {
local.push({ version: versionName, backend: backendName })
// Verify that the backend is really installed
for (const backendType of backendTypes) {
const backendName = await basename(backendType)
if (await isBackendInstalled(backendType, versionName)) {
local.push({ version: versionName, backend: backendName })
}
}
}
}