aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-29 01:05:58 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-06-29 01:08:54 +0200
commit5478b5dcf9544c680a8b175972445c31763f2814 (patch)
tree9126c7310beabc553d7beaacdf82e8a16440ed08
parentAdd describe procedure for vcomponents. (diff)
downloadcalp-5478b5dcf9544c680a8b175972445c31763f2814.tar.gz
calp-5478b5dcf9544c680a8b175972445c31763f2814.tar.xz
Calendar-import file write atomic.
-rw-r--r--module/vcomponent.scm30
1 files changed, 17 insertions, 13 deletions
diff --git a/module/vcomponent.scm b/module/vcomponent.scm
index e55b4f9b..01640bb8 100644
--- a/module/vcomponent.scm
+++ b/module/vcomponent.scm
@@ -84,26 +84,30 @@
(call-with-port (open-input-pipe "uuidgen")
read-line))
-(define (filepath calendar uid)
- (string-append (attr calendar 'X-HNH-DIRECTORY)
- file-name-separator-string
- uid ".ics"))
+(define / file-name-separator-string)
(define-public (calendar-import calendar event)
(case (attr calendar 'X-HNH-SOURCETYPE)
[(file)
(error "Importing into direct calendar files not supported")]
+
[(vdir)
- (aif (attr event 'UID)
- (with-output-to-file (filepath calendar it)
- (lambda () (print-components-with-fake-parent (list event))))
- (let ((uuid (uuidgen)))
- (set! (attr event 'UID) uuid)
- ;; TODO this should caputure attributes from the calendar
- (with-output-to-file (filepath calendar uuid)
- (lambda ()
- (print-components-with-fake-parent (list event))))))]
+ (let* ((uid (or (attr event 'UID) (uuidgen)))
+ ;; copy to enusre writable string
+ (tmpfile (string-copy (string-append (attr calendar 'X-HNH-DIRECTORY)
+ / ".calp-" uid "XXXXXX")))
+ (port (mkstemp! tmpfile)))
+ (set! (attr 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 (attr calendar 'X-HNH-DIRECTORY)
+ / uid ".ics"))
+ uid)]
+
[else
(error "Source of calendar unknown, aborting.")
]))