Better workaround for missing root folder. (#11046)

With the changes for asset directory the auto-creation condition was failing.

This should make it work again.
This commit is contained in:
James Dunkerley 2024-09-11 14:18:27 +01:00 committed by GitHub
parent a0a4a2fef3
commit a33376c8d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -139,16 +139,12 @@ export default class LocalBackend extends Backend {
): Promise<readonly backend.AnyAsset[]> {
const parentIdRaw = query.parentId == null ? null : extractTypeAndId(query.parentId).id
const parentId = query.parentId ?? newDirectoryId(this.projectManager.rootDirectory)
// Check if Root Directory Exists
if (
parentIdRaw == null &&
!(await this.projectManager.exists(this.projectManager.rootDirectory))
) {
await this.projectManager.createDirectory(this.projectManager.rootDirectory)
return []
} else {
// Catch the case where the directory does not exist.
let result: backend.AnyAsset[] = []
try {
const entries = await this.projectManager.listDirectory(parentIdRaw)
return entries
result = entries
.map((entry) => {
switch (entry.type) {
case projectManager.FileSystemEntryType.DirectoryEntry: {
@ -198,7 +194,21 @@ export default class LocalBackend extends Backend {
}
})
.sort(backend.compareAssets)
} catch (error) {
// Failed so check if exists
if (!(await this.projectManager.exists(parentIdRaw))) {
if (parentIdRaw === this.projectManager.rootDirectory) {
// Auto create the root directory
await this.projectManager.createDirectory(this.projectManager.rootDirectory)
result = []
} else {
// eslint-disable-next-line no-restricted-syntax
throw new Error('Directory does not exist.')
}
}
}
return result
}
/** Return a list of projects belonging to the current user.