1
2
3
4
5
6
7
8
9
10
11
12
13
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
+
|
#! /usr/bin/env tclsh
package require http 2.7
package require sqlite3
package require sha1
package require appfsd
package require platform
namespace eval ::appfs {
variable cachedir "/tmp/appfs-cache"
variable ttl 3600
variable nttl 60
# User-replacable function to convert a hostname/hash/method to an URL
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
+
-
+
|
if {$pathlen > 3} {
set retval(version) [lindex $path 3]
set retval(_children) files
set retval(_type) versions
set retval(package_sha1) [::appfs::db onecolumn {SELECT sha1 FROM packages WHERE hostname = $retval(hostname) AND os = $retval(os) AND cpuArch = $retval(cpu) AND version = $retval(version);}]
if {$retval(package_sha1) == ""} {
set retval(_children) dead
return [list]
return [array get retval]
}
if {$pathlen > 4} {
set retval(_type) files
set retval(file) [join [lrange $path 4 end] "/"]
} else {
set retval(file) ""
|
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
proc getattr {path} {
array set pathinfo [_parsepath $path]
array set retval [list]
switch -- $pathinfo(_type) {
"toplevel" - "sites" - "packages" - "os-cpu" - "versions" {
"toplevel" {
set retval(type) directory
set retval(childcount) 2;
}
"sites" {
set check [::appfs::db onecolumn {SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname);}]
if {$check == "1"} {
set retval(type) directory
set retval(childcount) 2;
}
}
"packages" {
set check [::appfs::db onecolumn {SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname) AND package = $pathinfo(package);}]
if {$check == "1"} {
set retval(type) directory
set retval(childcount) 2;
}
}
"os-cpu" {
if {$pathinfo(os) == "platform" && $pathinfo(cpu) == ""} {
set retval(type) symlink
set retval(source) [platform::generic]
} else {
set check [::appfs::db onecolumn {
SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname) AND package = $pathinfo(package) AND os = $pathinfo(os) AND cpuArch = $pathinfo(cpu);
}]
if {$check == "1"} {
set retval(type) directory
set retval(childcount) 2;
}
}
}
"versions" {
if {$pathinfo(version) == "latest"} {
set retval(type) symlink
set retval(source) "1.0"
} else {
if {[info exists pathinfo(package_sha1)] && $pathinfo(package_sha1) != ""} {
set retval(type) directory
set retval(childcount) 2;
}
}
}
"files" {
set retval(packaged) 1
set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
if {[file exists $localpath]} {
catch {
|