|
9 | 9 | {:file-name-prefix "mage"
|
10 | 10 | :hashed-directory-level 1})
|
11 | 11 |
|
12 |
| -(defn- md5 [^String data] |
13 |
| - (let [crypto (js/require "crypto")] |
14 |
| - (-> crypto (.createHash "md5") (.update data) (.digest "hex")))) |
15 |
| - |
16 | 12 | (defn- file-name-prefix []
|
17 | 13 | (:file-name-prefix options))
|
18 | 14 |
|
19 |
| -(defn- cache-id-prefix [] |
20 |
| - (str (subs (md5 (str (fs/realpath (mage/base-dir)) "/app/etc/")) 0 3) "_")) |
21 |
| - |
22 | 15 | (defn- chars-from-end [^String s length]
|
23 | 16 | (subs s (- (count s) length)))
|
24 | 17 |
|
25 | 18 | (defn- path [^String cache-dir ^String id]
|
26 | 19 | (let [length (:hashed-directory-level options)]
|
27 | 20 | (if (< 0 length)
|
28 |
| - (let [suffix (chars-from-end (md5 (str (cache-id-prefix) id)) length)] |
| 21 | + (let [suffix (chars-from-end (storage/md5 id) length)] |
29 | 22 | (str cache-dir (file-name-prefix) "--" suffix "/"))
|
30 | 23 | cache-dir)))
|
31 | 24 |
|
32 | 25 | (defn- tag-path [cache-dir]
|
33 | 26 | (str cache-dir (file-name-prefix) "-tags/"))
|
34 | 27 |
|
35 | 28 | (defn- id->filename [^String id]
|
36 |
| - (str (file-name-prefix) "---" (cache-id-prefix) id)) |
| 29 | + (str (file-name-prefix) "---" id)) |
37 | 30 |
|
38 | 31 | (defn- id->filepath [^String cache-dir ^String id]
|
39 | 32 | (str (path cache-dir id) (id->filename id)))
|
40 | 33 |
|
41 | 34 | (defn- tag->filepath [^String cache-dir ^String tag]
|
42 | 35 | (str (tag-path cache-dir) (id->filename tag)))
|
43 | 36 |
|
44 |
| -(defn- remove-cache-id-prefix [id-with-prefix] |
45 |
| - (subs id-with-prefix 4)) |
| 37 | +(defn- tag->ids [cache-dir tag] |
| 38 | + (let [file (tag->filepath cache-dir tag)] |
| 39 | + (if (fs/exists? file) |
| 40 | + (string/split-lines (fs/slurp file)) |
| 41 | + []))) |
| 42 | + |
| 43 | +(defn- delete [cache-dir id] |
| 44 | + (log/debug "Cleaning id" id) |
| 45 | + (let [file (id->filepath cache-dir id)] |
| 46 | + (when (fs/exists? file) |
| 47 | + (fs/rm file)))) |
46 | 48 |
|
47 | 49 | (defrecord File [cache-dir]
|
48 | 50 | storage/CacheStorage
|
49 | 51 |
|
50 |
| - (tag->ids [this tag] |
51 |
| - (let [file (tag->filepath cache-dir tag)] |
52 |
| - (if (fs/exists? file) |
53 |
| - (doall (map remove-cache-id-prefix (string/split-lines (fs/slurp file)))) |
54 |
| - []))) |
55 |
| - |
56 |
| - (delete [this id] |
57 |
| - (log/debug "Cleaning id" id) |
58 |
| - (let [file (id->filepath cache-dir id)] |
59 |
| - (when (fs/exists? file) |
60 |
| - (fs/rm file)))) |
61 |
| - |
62 | 52 | (clean-tag [this tag]
|
63 | 53 | (let [tag-file (tag->filepath cache-dir tag)]
|
64 | 54 | (log/debug "Tag-file" tag-file)
|
65 | 55 | (when (fs/exists? tag-file)
|
66 |
| - (run! #(storage/delete this %) (storage/tag->ids this tag)) |
| 56 | + (run! #(delete cache-dir %) (tag->ids cache-dir tag)) |
67 | 57 | (fs/rm tag-file))))
|
68 | 58 |
|
69 | 59 | (clean-all [this]
|
|
0 commit comments