34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
-
+
|
file mkdir [file dirname $file]
if {[file exists $file]} {
return $file
}
set tmpfile "${file}.[expr {rand()}]"
set tmpfile "${file}.[expr {rand()}][clock clicks]"
set fd [open $tmpfile "w"]
fconfigure $fd -translation binary
catch {
set token [::http::geturl $url -channel $fd -binary true]
}
|
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
+
|
return COMPLETE
}
proc _localpath {package hostname file} {
set homedir [::appfsd::get_homedir]
set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
return $dir
}
proc _parsepath {path} {
set path [string trim $path "/"]
set path [split $path "/"]
set pathlen [llength $path]
|
525
526
527
528
529
530
531
532
533
|
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
return -code error "No such file or directory"
}
return [array get retval]
}
proc openpath {path mode} {
array set pathinfo [_parsepath $path]
}
}
if {$pathinfo(_type) != "files"} {
return -code error "invalid type"
}
set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
if {[file exists $localpath]} {
return $localpath
}
set work [split $pathinfo(file) "/"]
set directory [join [lrange $work 0 end-1] "/"]
set file [lindex $work end]
set file_sha1 [::appfs::db onecolumn {SELECT file_sha1 FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;}]
if {$file_sha1 == ""} {
return -code error "No such file or directory"
}
set localcachefile [download $pathinfo(hostname) $file_sha1]
if {$mode == "create"} {
set tmplocalpath "${localpath}.[expr rand()][clock clicks]"
file copy -force -- $localcachefile $tmplocalpath
file rename -force -- $tmplocalpath $localpath
return $localpath
}
return $localcachefile
}
}
|