From 55f80b2ca4c8d44255e38ef2eee4564501aa83ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 17 Aug 2020 18:23:08 +0200 Subject: MOORE --- module/vcomponent/vdir/save-delete.scm | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 module/vcomponent/vdir/save-delete.scm (limited to 'module/vcomponent/vdir/save-delete.scm') diff --git a/module/vcomponent/vdir/save-delete.scm b/module/vcomponent/vdir/save-delete.scm new file mode 100644 index 00000000..02db9d7a --- /dev/null +++ b/module/vcomponent/vdir/save-delete.scm @@ -0,0 +1,55 @@ +;;; Commentary: +;;; Module for writing components to the vdir storage format. +;;; Currently also has some cases for "big" icalendar files, +;;; but those are currently unsupported. + +;;; TODO generalize save-event and remove-event into a general interface, +;;; which different database backends can implement. Actually, do that for all +;;; loading and writing. + +;;; Code: + +(define-module (vcomponent vdir save-delete) + :use-module (util) + :use-module (vcomponent ical output) + :use-module (vcomponent) + :use-module ((util io) :select (with-atomic-output-to-file)) + ) + + +(define / file-name-separator-string) + +(define-public (save-event event) + (define calendar (parent event)) + (case (prop calendar '-X-HNH-SOURCETYPE) + [(file) + (error "Importing into direct calendar files not supported")] + + [(vdir) + (let* ((uid (or (prop event 'UID) (uuidgen)))) + (set! (prop event 'UID) uid + ;; TODO use existing filename if present? + (prop event '-X-HNH-FILENAME) (string-append + (prop calendar '-X-HNH-DIRECTORY) + / uid ".ics")) + (with-atomic-output-to-file (prop event '-X-HNH-FILENAME) + (lambda () (print-components-with-fake-parent (list event)))) + uid)] + + [else + (error "Source of calendar unknown, aborting.") + ])) + + +(define-public (remove-event event) + (define calendar (parent event)) + (case (prop calendar '-X-HNH-SOURCETYPE) + [(file) + (error "Removing events from large files unsupported")] + + [(vdir) + (delete-file (prop event '-X-HNH-FILENAME))] + + [else + (error "Source of calendar unknown, aborting.") + ])) -- cgit v1.2.3