(uri, patchObject)
| 683 | } |
| 684 | |
| 685 | async patch (uri, patchObject) { |
| 686 | if (overQuota(this.quotaFile, this.quota)) { |
| 687 | debug.handlers('PATCH -- Over quota') |
| 688 | throw error(413, 'Storage quota exceeded') |
| 689 | } |
| 690 | |
| 691 | const url = uri |
| 692 | let path |
| 693 | try { |
| 694 | ({ path } = await this.resourceMapper.mapUrlToFile({ url })) |
| 695 | } catch (err) { |
| 696 | throw error(err.status || 500, err.message) |
| 697 | } |
| 698 | |
| 699 | await withLock(path, async () => { |
| 700 | let originalData = '' |
| 701 | |
| 702 | try { |
| 703 | originalData = await promisify(fs.readFile)(path, { encoding: 'utf8' }) |
| 704 | } catch (err) { |
| 705 | throw error(err, 'Cannot patch a file that does not exist') |
| 706 | } |
| 707 | |
| 708 | const contentType = getContentType(path) |
| 709 | const patchedData = await this.applyPatch(originalData, patchObject, contentType, uri) |
| 710 | |
| 711 | // Write patched data back to file |
| 712 | await promisify(fs.writeFile)(path, patchedData, 'utf8') |
| 713 | }) |
| 714 | |
| 715 | await clearAclCache() |
| 716 | |
| 717 | debug.handlers('PATCH -- Patched:' + path) |
| 718 | } |
| 719 | |
| 720 | async applyPatch (data, patchObject, contentType, uri) { |
| 721 | const baseGraph = $rdf.graph() |
no test coverage detected