diff --git a/src/storage/DataAccessorBasedStore.ts b/src/storage/DataAccessorBasedStore.ts index 5cfcf7bc3..c03dd75ca 100644 --- a/src/storage/DataAccessorBasedStore.ts +++ b/src/storage/DataAccessorBasedStore.ts @@ -385,7 +385,9 @@ export class DataAccessorBasedStore implements ResourceStore { } catch (error: unknown) { if (NotFoundHttpError.isInstance(error)) { // Make sure the parent exists first - await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container)); + if (!this.identifierStrategy.isRootContainer(container)) { + await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container)); + } await this.writeData(container, new BasicRepresentation([], container), true); } else { throw error; diff --git a/test/unit/storage/DataAccessorBasedStore.test.ts b/test/unit/storage/DataAccessorBasedStore.test.ts index 8cc5af2f6..4fcb51412 100644 --- a/test/unit/storage/DataAccessorBasedStore.test.ts +++ b/test/unit/storage/DataAccessorBasedStore.test.ts @@ -305,6 +305,14 @@ describe('A DataAccessorBasedStore', (): void => { expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined(); }); + it('can write resources even if root does not exist.', async(): Promise => { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete accessor.data[root]; + const resourceID = { path: `${root}resource` }; + await expect(store.setRepresentation(resourceID, representation)).resolves.toBeUndefined(); + await expect(arrayifyStream(accessor.data[resourceID.path].data)).resolves.toEqual([ resourceData ]); + }); + it('can write containers with quad data.', async(): Promise => { const resourceID = { path: `${root}container/` };