forked from hummypkg/webif
60 lines
1.0 KiB
Plaintext
60 lines
1.0 KiB
Plaintext
|
#!/mod/bin/jimsh
|
||
|
|
||
|
source /mod/webif/lib/setup
|
||
|
require system.class ts.class
|
||
|
|
||
|
proc do_shrink {ts} {
|
||
|
if {[$ts flag "Shrunk"]} { return }
|
||
|
|
||
|
set file [file rootname [$ts get file]]
|
||
|
|
||
|
if {[$ts inuse]} { return }
|
||
|
|
||
|
if {[catch {
|
||
|
set perc [exec /mod/bin/stripts -aq $file]
|
||
|
} msg]} {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if {[string match {*%} $perc]} {
|
||
|
set perc [string range $perc 0 end-1]
|
||
|
} else {
|
||
|
set perc 0
|
||
|
}
|
||
|
|
||
|
if {$perc == 0} {
|
||
|
puts " Flagging $file as shrunk..."
|
||
|
$ts set_shrunk
|
||
|
}
|
||
|
}
|
||
|
|
||
|
proc entries {dir callback} {
|
||
|
foreach entry [readdir -nocomplain $dir] {
|
||
|
if {![string match {*.ts} $entry} continue
|
||
|
if {[catch {set ts [ts fetch "$dir/$entry"]}]} continue
|
||
|
if {$ts == 0} continue
|
||
|
$callback $ts
|
||
|
}
|
||
|
}
|
||
|
|
||
|
proc scan {dir} {
|
||
|
puts "Scanning $dir..."
|
||
|
file stat "$dir/" st
|
||
|
if {$st(dev) != $::rootdev} { return }
|
||
|
|
||
|
entries $dir do_shrink
|
||
|
|
||
|
foreach entry [readdir -nocomplain $dir] {
|
||
|
if {[file isdirectory "$dir/$entry"]} {
|
||
|
scan "$dir/$entry"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
set root [system mediaroot]
|
||
|
file stat "$root/" rootstat
|
||
|
set rootdev $rootstat(dev)
|
||
|
|
||
|
scan $root
|
||
|
|