~subsetpark/bagatto

ref: c22c5b081d01751c3ed14046b11ffff11cebbfa6 bagatto/src/util.janet -rw-r--r-- 599 bytes
c22c5b08 — Zach Smith Cache path creation 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Stolen from
# https://github.com/pyrmont/ecstatic/blob/master/src/ecstatic/utilities.janet
(defn mkpath
  [dirpath cache]
  (when (not (empty? dirpath))
    (let [path @""]
      (each dir (string/split "/" dirpath)
        (if (not (empty? path))
          (buffer/push-string path "/"))
        (buffer/push-string path dir)
        (let [s (string path)]
          (unless (in cache s)
            (os/mkdir s)
            (put cache s true)))))))

(defn copy-file
  [source dest cache]
  (case ((os/stat source) :mode)
    :file (spit dest (slurp source))
    :directory (mkpath dest cache)))