~subsetpark/bagatto

ref: 075f758e48bb282b35b0df18a703af68da96e0c1 bagatto/src/util.janet -rw-r--r-- 593 bytes
075f758e — Zach Smith Tweak subtitle 9 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)
    :directory (mkpath dest cache)
    (spit dest (slurp source))))