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[]> { ): Promise<readonly backend.AnyAsset[]> {
const parentIdRaw = query.parentId == null ? null : extractTypeAndId(query.parentId).id const parentIdRaw = query.parentId == null ? null : extractTypeAndId(query.parentId).id
const parentId = query.parentId ?? newDirectoryId(this.projectManager.rootDirectory) const parentId = query.parentId ?? newDirectoryId(this.projectManager.rootDirectory)
// Check if Root Directory Exists
if ( // Catch the case where the directory does not exist.
parentIdRaw == null && let result: backend.AnyAsset[] = []
!(await this.projectManager.exists(this.projectManager.rootDirectory)) try {
) {
await this.projectManager.createDirectory(this.projectManager.rootDirectory)
return []
} else {
const entries = await this.projectManager.listDirectory(parentIdRaw) const entries = await this.projectManager.listDirectory(parentIdRaw)
return entries result = entries
.map((entry) => { .map((entry) => {
switch (entry.type) { switch (entry.type) {
case projectManager.FileSystemEntryType.DirectoryEntry: { case projectManager.FileSystemEntryType.DirectoryEntry: {
@ -198,8 +194,22 @@ export default class LocalBackend extends Backend {
} }
}) })
.sort(backend.compareAssets) .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. /** Return a list of projects belonging to the current user.
* @throws An error if the JSON-RPC call fails. */ * @throws An error if the JSON-RPC call fails. */