~subsetpark/bagatto

ref: 38335683a141402f16ca4dcddce8328819d63083 bagatto/src/util.janet -rw-r--r-- 593 bytes
38335683 — Zach Smith Some simplification of threading code 1 year, 6 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))))