aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/util/parse-cal-path.scm
blob: 33dbd0ccf24b8f8507ae0aff9c3766b0c7608320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;;; TODO remove this module, it should be part of the vdir interface

(define-module (vcomponent util parse-cal-path)
  :use-module (hnh util)
  :use-module ((calp util time) :select (report-time!))
  :use-module (vcomponent base)
  :use-module (calp translation)
  :use-module ((vcomponent formats ical parse)
               :select (parse-calendar))
  :use-module ((vcomponent formats vdir parse)
               :select (parse-vdir))
  :export (parse-cal-path))


;; Parse a vdir or ics file at the given path.
(define (parse-cal-path path)
  ;; TODO check (access? path R_OK) ?
  (define st (stat path))
  (define cal
    (case (stat:type st)
      [(regular)
       (prop (call-with-input-file path parse-calendar)
             '-X-HNH-SOURCETYPE 'file)]
      [(directory)
       (report-time! (G_ "Parsing ~a") path)
       (set-properties (parse-vdir path)
                       (cons '-X-HNH-SOURCETYPE 'vdir)
                       (cons '-X-HNH-DIRECTORY path))]
      [(block-special char-special fifo socket unknown symlink)
       => (lambda (t) (scm-error 'misc-error "parse-cal-path"
                            (G_ "Can't parse file of type ~s")
                            (list t)
                            #f))]))

  (if (prop cal 'NAME)
      cal
      (prop cal 'NAME
            (or (prop cal 'X-WR-CALNAME)
                (string-append "[" (basename path) "]")))))