fix: Prevent parent containers from storing generated metadata

This commit is contained in:
Joachim Van Herwegen
2021-09-03 15:39:57 +02:00
parent 1e1edd5c67
commit 7f3eab0b20
2 changed files with 32 additions and 10 deletions

View File

@@ -268,9 +268,7 @@ export class DataAccessorBasedStore implements ResourceStore {
deleted.push(container);
// Update modified date of parent
const parentMetadata = await this.accessor.getMetadata(container);
updateModifiedDate(parentMetadata);
await this.accessor.writeContainer(container, parentMetadata);
await this.updateContainerModifiedDate(container);
}
await this.accessor.deleteResource(identifier);
@@ -386,15 +384,11 @@ export class DataAccessorBasedStore implements ResourceStore {
}
// Parent container is also modified
const parentMetadata = await this.accessor.getMetadata(container);
updateModifiedDate(parentMetadata);
await this.accessor.writeContainer(container, parentMetadata);
await this.updateContainerModifiedDate(container);
}
// Remove all generated metadata to prevent it from being stored permanently
representation.metadata.removeQuads(
representation.metadata.quads(null, null, null, SOLID_META.terms.ResponseMetadata),
);
this.removeResponseMetadata(representation.metadata);
await (isContainer ?
this.accessor.writeContainer(identifier, representation.metadata) :
@@ -438,6 +432,25 @@ export class DataAccessorBasedStore implements ResourceStore {
representation.metadata.addQuads(quads);
}
/**
* Removes all generated data from metadata to prevent it from being stored permanently.
*/
protected removeResponseMetadata(metadata: RepresentationMetadata): void {
metadata.removeQuads(
metadata.quads(null, null, null, SOLID_META.terms.ResponseMetadata),
);
}
/**
* Updates the last modified date of the given container
*/
protected async updateContainerModifiedDate(container: ResourceIdentifier): Promise<void> {
const parentMetadata = await this.accessor.getMetadata(container);
updateModifiedDate(parentMetadata);
this.removeResponseMetadata(parentMetadata);
await this.accessor.writeContainer(container, parentMetadata);
}
/**
* Generates a new URI for a resource in the given container, potentially using the given slug.
*