12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
+
-
+
-
+
+
+
+
+
+
+
+
+
+
-
+
|
}
append retval "[string range $hash [expr {$idx * 2}] end]"
return $retval
}
proc _cachefile {url key {keyIsHash 1}} {
set filekey $key
if {$keyIsHash} {
set key [_hash_sep $key]
set filekey [_hash_sep $filekey]
}
set file [file join $::appfs::cachedir $key]
set file [file join $::appfs::cachedir $filekey]
file mkdir [file dirname $file]
if {![file exists $file]} {
set tmpfile "${file}.new"
set fd [open $tmpfile "w"]
fconfigure $fd -translation binary
set token [::http::geturl $url -channel $fd -binary true]
set ncode [::http::ncode $token]
::http::reset $token
close $fd
if {$keyIsHash} {
catch {
set hash [string tolower [exec openssl sha1 $tmpfile]]
regsub {.*= *} $hash {} hash
}
} else {
set hash $key
}
if {$ncode == "200"} {
if {$ncode == "200" && $hash == $key} {
file rename -force -- $tmpfile $file
} else {
file delete -force -- $tmpfile
}
}
return $file
|