From c6e2bf633d435e52813f03da0691a99a91890c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 8 Jul 2020 02:21:28 +0200 Subject: Move save-event to own module. This hopefully resolves theh problems with (output ical) having bootstraping problems. --- module/output/vdir.scm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 module/output/vdir.scm (limited to 'module/output/vdir.scm') diff --git a/module/output/vdir.scm b/module/output/vdir.scm new file mode 100644 index 00000000..5c70f28e --- /dev/null +++ b/module/output/vdir.scm @@ -0,0 +1,39 @@ +;;; Commentary: +;;; Module for writing components to the vdir storage format. +;;; Currently also has some cases for "big" icalendar files, +;;; but those are currently unsupported. +;;; Code: + +(define-module (output vdir) + :use-module (util) + :use-modules (output ical) + :use-modules (vcomponent) + ) + +(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))) + ;; copy to enusre writable string + (tmpfile (string-copy (string-append (prop calendar 'X-HNH-DIRECTORY) + / ".calp-" uid "XXXXXX"))) + (port (mkstemp! tmpfile))) + (set! (prop event 'UID) uid) + (with-output-to-port port + (lambda () (print-components-with-fake-parent (list event)))) + ;; does close flush? + (force-output port) + (close-port port) + (rename-file tmpfile (string-append (prop calendar 'X-HNH-DIRECTORY) + / uid ".ics")) + uid)] + + [else + (error "Source of calendar unknown, aborting.") + ])) -- cgit v1.2.3