@@ -4,27 +4,30 @@ Rebol [
4
4
name: thru-cache
5
5
type: module
6
6
options: [delay]
7
- version: 0.1 .0
8
- exports: [path-thru read-thru load-thru do-thru clear-thru]
7
+ version: 0.2 .0
8
+ exports: [path-thru read-thru load-thru do-thru clear-thru list-thru exists-thru? ]
9
9
author: @Oldes
10
10
file: %thru-cache.reb
11
11
home: https://src.rebol.tech/modules/thru-cache.reb
12
12
]
13
13
14
+ ;; Initialize the directory for storing local files
15
+ so: system/options
16
+ unless select so 'thru-cache [
17
+ put so 'thru-cache join to-real-file any [
18
+ get-env "TEMP"
19
+ so/data
20
+ ] %thru-cache/
21
+ sys/log/info 'REBOL ["Using thru-cache:" mold so/thru-cache ]
22
+ ]
23
+
14
24
path-thru : func [
15
25
{Returns the local disk cache path of a remote file}
16
26
url [url! ] "Remote file address"
17
27
return: [file! ]
18
- /local so hash file path
28
+ /local hash file path
19
29
] [
20
- so: system/options
21
- unless select so 'thru-cache [
22
- put so 'thru-cache join to-real-file any [
23
- get-env "TEMP"
24
- so/data
25
- ] %thru-cache/
26
- sys/log/info 'REBOL ["Using thru-cache:" mold so/thru-cache ]
27
- ]
30
+ unless find so 'thru-cache [return none]
28
31
hash: checksum form url 'MD5
29
32
file: head (remove back tail remove remove (form hash))
30
33
path: dirize append copy so/thru-cache copy/part file 2
@@ -83,19 +86,19 @@ do-thru: func [
83
86
84
87
clear-thru : func [
85
88
"Removes local disk cache files"
86
- /only filter [string! ] "Delete only files where the filter is found "
89
+ /only filter [string! ] "Delete only the files that match the filter"
87
90
/test "Only print files to be deleted"
88
91
/local temp dir log
89
92
] [
90
- unless exists? dir: select system /options 'thru-cache [exit]
93
+ unless exists? dir: select so 'thru-cache [exit]
91
94
log: dir/read-thru.log
92
95
if test [
93
96
unless exists? log [exit]
94
97
filter: any [filter "*" ]
95
98
foreach [path url] transcode read log [
96
99
if all [
97
100
exists? dir/: path
98
- find/any url filter
101
+ find/any/match url filter
99
102
][ print [as-green skip path 3 url] ]
100
103
]
101
104
exit
@@ -118,8 +121,23 @@ clear-thru: func [
118
121
()
119
122
]
120
123
124
+ exists-thru? : func [
125
+ "Returns true if the remote file is present in the local disk cache"
126
+ url [url! file! ] "Remote file address"
127
+ ] [
128
+ exists? any [all [file? url url] path-thru url]
129
+ ]
130
+
131
+ list-thru : func [
132
+ "Prints localy stored URLs"
133
+ /only filter [string! ] "List only the files that match the filter"
134
+ ] [
135
+ sys/log/info 'REBOL ["Used thru-cache directory:" mold so/thru-cache ]
136
+ clear-thru/: only/test filter
137
+ ]
138
+
121
139
log-thru-file : func [ path url] [
122
- write /append system /options /thru-cache/read-thru.log ajoin [
123
- #"%" copy/part tail path -32 SP url LF
140
+ write /append so /thru-cache/read-thru.log ajoin [
141
+ #"%" copy/part tail path -32 SP mold url LF
124
142
]
125
143
]
0 commit comments