diff --git a/CONTROL/control b/CONTROL/control index 186f0450..fd81d7b1 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,10 +1,10 @@ Package: webif Priority: optional Section: web -Version: 1.3.5-2 +Version: 1.3.5-3 Architecture: mipsel Maintainer: af123@hpkg.tv -Depends: tcpfix,webif-channelicons(>=1.1.24),lighttpd(>=1.4.39-1),jim(>=0.77),jim-oo(>=0.77),jim-sqlite3(>=0.76),jim-cgi(>=0.7-1),jim-binary(>=0.76),service-control(>=2.3),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.5),hmt(>=2.0.10),ssmtp,cron-daemon(>=1.18.3-3),at(>=3.1.18),anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.1.9),webif-charts(>=1.2-1),stripts(>=1.2.5-3),tmenu(>=1.21-1),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7),hwctl,nugget(>=0.95),sqlite3(>=3.15.1) +Depends: tcpfix,webif-channelicons(>=1.1.24),lighttpd(>=1.4.39-1),jim(>=0.77),jim-oo(>=0.77),jim-sqlite3(>=0.76),jim-cgi(>=0.7-1),jim-binary(>=0.76),service-control(>=2.3),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.5),hmt(>=2.0.10),ssmtp,cron-daemon(>=1.18.3-3),at(>=3.1.18),anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.1.9),webif-charts(>=1.2-1),stripts(>=1.2.5-3),tmenu(>=1.21-2),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7),hwctl,nugget(>=0.95),sqlite3(>=3.15.1) Suggests: Description: An evolving web interface for the Humax. Tags: http://hummy.tv/forum/threads/7619/ diff --git a/webif/html/browse/queue.jim b/webif/html/browse/queue.jim index 9ddbe196..a6090d31 100755 --- a/webif/html/browse/queue.jim +++ b/webif/html/browse/queue.jim @@ -28,15 +28,16 @@ foreach file [cgi_get files] { if {$ts eq "0"} continue if {$act eq "mp2"} { - set q [queue insert $ts mp3] + set q [queue insert -hold $ts mp3] } else { - set q [queue insert $ts $act] + set q [queue insert -hold $ts $act] } switch -- $act { mp2 { $q set args "-mp2" } mp3 { $q set args "-mp3" } } + $q submit puts "" } puts "" diff --git a/webif/html/browse/script.js b/webif/html/browse/script.js index cc8ac202..517399ea 100755 --- a/webif/html/browse/script.js +++ b/webif/html/browse/script.js @@ -403,6 +403,7 @@ function flagdir(file, flag, iconset, output, options) .empty() .html(' Updating...') .load('/browse/iconset.jim', { file: file }); + flag = flag.toLowerCase(); if ($(options).attr(flag) == '1') $(options).attr(flag, 0); else @@ -682,7 +683,7 @@ var dmenuclick = function(action, el, pos) break; case 'shrinkr': - flagdir(file, 'autoshrinkr', iconset, results, el); + flagdir(file, 'autoshrinkR', iconset, results, el); break; case 'decrypt': @@ -690,7 +691,7 @@ var dmenuclick = function(action, el, pos) break; case 'decryptr': - flagdir(file, 'autodecryptr', iconset, results, el); + flagdir(file, 'autodecryptR', iconset, results, el); break; case 'resetnew': diff --git a/webif/html/diag/queue/fetch.jim b/webif/html/diag/queue/fetch.jim index b60a7ef2..77db0062 100755 --- a/webif/html/diag/queue/fetch.jim +++ b/webif/html/diag/queue/fetch.jim @@ -24,6 +24,12 @@ foreach q [queue all] { } [$q get file]] set submitted [clock format [$q get submitted] \ -format {%d/%m/%Y %H:%M:%S}] + if {[$q get last] ne "0"} { + set last [clock format [$q get last] \ + -format {%d/%m/%Y %H:%M:%S}] + } else { + set last "" + } set start [$q get start] if {$start ne "0"} { set start $($start - [clock seconds]) } @@ -32,6 +38,7 @@ foreach q [queue all] { puts "{" puts " \"qid\": [$q get id]," puts " \"submitted\": \"$submitted\"," + puts " \"last\": \"$last\"," puts " \"file\": \"[::json::escape $name]\"," puts " \"action\": \"[::json::escape [$q get action]]\"," puts " \"args\": \"[::json::escape [$q get args]]\"," diff --git a/webif/html/diag/queue/index.jim b/webif/html/diag/queue/index.jim index 9f33ec6c..51cdb37c 100755 --- a/webif/html/diag/queue/index.jim +++ b/webif/html/diag/queue/index.jim @@ -33,8 +33,9 @@ There are no tasks in the queue. File Action Status - Time + Runtime Log + Last Update diff --git a/webif/html/diag/queue/script.js b/webif/html/diag/queue/script.js index 7ebb8e65..433f5a15 100644 --- a/webif/html/diag/queue/script.js +++ b/webif/html/diag/queue/script.js @@ -38,6 +38,7 @@ function load() s += v.runtime; s += '' + '' + v.log + '' + + '' + v.last + '' + ''; $('#queuetab > tbody').append(s); diff --git a/webif/html/sched/rpc/manual.jim b/webif/html/sched/rpc/manual.jim index f07a3776..74ce5128 100755 --- a/webif/html/sched/rpc/manual.jim +++ b/webif/html/sched/rpc/manual.jim @@ -33,10 +33,10 @@ if {[llength $errfields]} { set r [rsv manual $start $end $lcn $type $repeat $title] } msg]} { puts "\"status\": 0," - puts "\"err\": \"$msg\"" + puts "\"err\": \"c: $msg\"" } elseif {[catch {$r insert} msg]} { puts "\"status\": 0," - puts "\"err\": \"$msg\"" + puts "\"err\": \"i: $msg\"" } else { puts "\"status\": 1" system restartpending diff --git a/webif/lib/auto/NOTES b/webif/lib/auto/NOTES index 67b5fd9f..0c45743f 100644 --- a/webif/lib/auto/NOTES +++ b/webif/lib/auto/NOTES @@ -40,6 +40,14 @@ Plugins register themselves with: If not specified, priority defaults to 500. +Plugins should use directory flags of the form .auto[R] with the +optional trailing R indicating recursion. If they use filesystem flags +that don't conform to this scheme then they should register them with: + + ::auto::register_flag + + (e.g. ::auto::register_flag sweeper sweeper) + The framework will call the following callbacks (if defined within the module): ::module::init @@ -86,7 +94,7 @@ The following functions are available for modules to use: Check if a recording is in use (with retries). - ::auto::autoflagscan + ::auto::flagscan Starting at the directory indicated by , all directories are recursively scanned looking for those containing a file named @@ -102,18 +110,6 @@ The following functions are available for modules to use: If the callback returns the string "STOP" then the directory scan stops. - ::auto::flagscan - - Starting at the directory indicated by , all directories are - recursively scanned looking for those containing a file named - ".". - - The callback will be called once for each flagged directory with - the directory name passed as the sole argument. - - If the callback returns the string "STOP" then the directory - scan stops. - ::auto::direntries Scan the named directory and call the callback for each loadable diff --git a/webif/lib/auto/deq b/webif/lib/auto/deq index 6c94630c..8c142b41 100755 --- a/webif/lib/auto/deq +++ b/webif/lib/auto/deq @@ -15,7 +15,7 @@ set ::auto::force 0 while {[llength $argv]} { switch -- [lindex $argv 0] { -d { - set ::auto::loglevel 2 + incr ::auto::loglevel set ::auto::logfd stdout } -f { @@ -151,9 +151,12 @@ proc ::auto::pending {} { }] [queue pending]] } +set ::auto::processed 0 for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} { ::auto::dumpq $qq + incr ::auto::processed + # Try to run the first item in the queue. set q [lindex $qq 0] set plugin [$q get action] @@ -169,7 +172,7 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} { ::auto::dsc ::auto::oktorun - $q update RUNNING "Started at [::auto::date]" + $q update RUNNING "Started" set ologprefix $::auto::logprefix set ::auto::logprefix "$plugin:$::auto::logprefix" @@ -184,11 +187,11 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} { ::auto::log " $code - $msg - $next" 0 switch -- $code { "-1" { - ::auto::log " Plugin failure." 0 + ::auto::log " Plugin failure" 0 $q update "FAILED" "Plugin failure" 1 } "OK" { - $q update "COMPLETE" "$msg ([::auto::date])" 1 $elapsed + $q update "COMPLETE" $msg 1 $elapsed ::auto::runplugins dequeued $plugin $q $ts } "DEFER" { @@ -197,7 +200,7 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} { } "FAILED" { $q update "FAILED" $msg 1 $elapsed } default { - $q update "FAILED" "Unknown response '$code' from plugin" + $q update "FAILED" "Unknown response '$code'" } } } @@ -207,5 +210,10 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} { release_lock webif_autodeq -::auto::log "Auto de-queue completed in [::auto::elapsed $scanstart] seconds." +if {$::auto::processed || $::auto::loglevel > 1} { + set q "s" + if {$::auto::processed == 1} { set q "" } + ::auto::log "Auto de-queue processed $::auto::processed item$q in [\ + ::auto::elapsed $scanstart] seconds." +} diff --git a/webif/lib/auto/plugin/decrypt/auto.hook b/webif/lib/auto/plugin/decrypt/auto.hook index 6e0eff93..c89b5737 100755 --- a/webif/lib/auto/plugin/decrypt/auto.hook +++ b/webif/lib/auto/plugin/decrypt/auto.hook @@ -32,21 +32,15 @@ proc ::decrypt::ts {ts} { } proc ::decrypt::directory {dir} { - ::auto::log "DECRYPT: \[$dir]" 2 ::auto::direntries $dir ::decrypt::ts } proc ::decrypt::rundir {dir} { - set sup [::auto::autoflagscanup $dir decrypt] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir decrypt ::decrypt::directory 0 $sup + ::auto::flagscan $dir decrypt ::decrypt::directory 0 } proc ::decrypt::run {} { - ::auto::autoflagscan $::auto::root decrypt ::decrypt::directory + ::auto::flagscan $::auto::root decrypt ::decrypt::directory } ::auto::register decrypt 600 diff --git a/webif/lib/auto/plugin/dedup/auto.hook b/webif/lib/auto/plugin/dedup/auto.hook index 3d6f74f6..8b0de88b 100755 --- a/webif/lib/auto/plugin/dedup/auto.hook +++ b/webif/lib/auto/plugin/dedup/auto.hook @@ -2,7 +2,6 @@ proc ::dedup::directory {dir} { namespace import ::auto::log - log "DEDUP: \[$dir]" 2 loop i 0 1 { foreach line [split \ [exec /mod/webif/html/dedup/dedup -yes -auto $dir] "\n"] { @@ -13,16 +12,11 @@ proc ::dedup::directory {dir} { } proc ::dedup::rundir {dir} { - set sup [::auto::autoflagscanup $dir dedup] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir dedup ::dedup::directory 0 $sup + ::auto::flagscan $dir dedup ::dedup::directory 0 } proc ::dedup::run {} { - ::auto::autoflagscan $::auto::root dedup ::dedup::directory + ::auto::flagscan $::auto::root dedup ::dedup::directory } ::auto::register dedup 800 diff --git a/webif/lib/auto/plugin/expire/auto.hook b/webif/lib/auto/plugin/expire/auto.hook index 025d77b6..ddc1f195 100755 --- a/webif/lib/auto/plugin/expire/auto.hook +++ b/webif/lib/auto/plugin/expire/auto.hook @@ -2,8 +2,6 @@ proc ::expire::directory {dir} { namespace import ::auto::log - log "EXPIRE: \[$dir]" 2 - # type 0 keep {} days 2 keepnew 0 set ax [dir expiry $dir] log " $ax" 2 @@ -74,16 +72,11 @@ proc ::expire::directory {dir} { } proc ::expire::rundir {dir} { - set sup [::auto::autoflagscanup $dir expire] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir expire ::expire::directory 0 $sup + ::auto::flagscan $dir expire ::expire::directory 0 } proc ::expire::run {} { - ::auto::autoflagscan $::auto::root expire ::expire::directory + ::auto::flagscan $::auto::root expire ::expire::directory } ::auto::register expire 900 diff --git a/webif/lib/auto/plugin/mp3/auto.hook b/webif/lib/auto/plugin/mp3/auto.hook index b7b51186..5f75c819 100755 --- a/webif/lib/auto/plugin/mp3/auto.hook +++ b/webif/lib/auto/plugin/mp3/auto.hook @@ -24,27 +24,20 @@ proc ::mp3::ts {ts} { } # Enqueue file - set q [queue insert $ts mp3] - #$q set args "-mp2" + queue insert $ts mp3 ::auto::log " $file - Queued for mp3." 0 } proc ::mp3::directory {dir} { - ::auto::log "MP3: \[$dir]" 2 ::auto::direntries $dir ::mp3::ts } proc ::mp3::rundir {dir} { - set sup [::auto::autoflagscanup $dir mp3] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir mp3 ::mp3::directory 0 $sup + ::auto::flagscan $dir mp3 ::mp3::directory 0 } proc ::mp3::run {} { - ::auto::autoflagscan $::auto::root mp3 ::mp3::directory + ::auto::flagscan $::auto::root mp3 ::mp3::directory } ::auto::register mp3 300 diff --git a/webif/lib/auto/plugin/mpg/auto.hook b/webif/lib/auto/plugin/mpg/auto.hook index f33e51b9..4c8ede95 100755 --- a/webif/lib/auto/plugin/mpg/auto.hook +++ b/webif/lib/auto/plugin/mpg/auto.hook @@ -29,21 +29,15 @@ proc ::mpg::ts {ts} { } proc ::mpg::directory {dir} { - ::auto::log "MPG: \[$dir]" 2 ::auto::direntries $dir ::mpg::ts } proc ::mpg::rundir {dir} { - set sup [::auto::autoflagscanup $dir mpg] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir mpg ::mpg::directory 0 $sup + ::auto::flagscan $dir mpg ::mpg::directory 0 } proc ::mpg::run {} { - ::auto::autoflagscan $::auto::root mpg ::mpg::directory + ::auto::flagscan $::auto::root mpg ::mpg::directory } ::auto::register mpg 300 diff --git a/webif/lib/auto/plugin/shrink/auto.hook b/webif/lib/auto/plugin/shrink/auto.hook index 072a8bc1..046ad23d 100755 --- a/webif/lib/auto/plugin/shrink/auto.hook +++ b/webif/lib/auto/plugin/shrink/auto.hook @@ -41,21 +41,15 @@ proc ::shrink::ts {ts} { } proc ::shrink::directory {dir} { - ::auto::log "SHRINK: \[$dir]" 2 ::auto::direntries $dir ::shrink::ts } proc ::shrink::rundir {dir} { - set sup [::auto::autoflagscanup $dir shrink] - if {$sup == -1} { - log "Encountered special directory." 2 - return - } - ::auto::autoflagscan $dir shrink ::shrink::directory 0 $sup + ::auto::flagscan $dir shrink ::shrink::directory 0 } proc ::shrink::run {} { - ::auto::autoflagscan $::auto::root shrink ::shrink::directory + ::auto::flagscan $::auto::root shrink ::shrink::directory } ::auto::register shrink 400 diff --git a/webif/lib/auto/scan b/webif/lib/auto/scan index ee442ad2..6db7faa3 100755 --- a/webif/lib/auto/scan +++ b/webif/lib/auto/scan @@ -17,7 +17,7 @@ set ::auto::force 0 while {[llength $argv]} { switch -- [lindex $argv 0] { -d { - set ::auto::loglevel 2 + incr ::auto::loglevel set ::auto::logfd stdout } -f { @@ -71,7 +71,8 @@ if {!$::auto::force} { set autofreq [$::auto::settings autofreq] if {$autofreq == 0} { set autofreq 10 } - set timesincelast $(([clock seconds] - [$::auto::settings autolast]) / 60) + set timesincelast $(([clock seconds] - [$::auto::settings autolast]) \ + / 60) if {$timesincelast < $autofreq} { ::auto::log "Aborting, not yet time to run." 2 ::auto::log " elapsed (minutes): $timesincelast (<$autofreq)" 2 @@ -108,6 +109,93 @@ set ::auto::rootdev $rootstat(dev) ######################################################################### # Utility functions +set ::auto::flagdb {} +set ::auto::activeflags {} +set ::auto::extraflags {} + +proc ::auto::buildflagdb {dir {active {}}} {{seen {}} {indent 0}} { + variable flagdb + variable activeflags + variable extraflags + variable dustbin + variable rootdev + + incr indent 2 + log "[string repeat " " $indent]\[$dir]" 3 + + if {$dir eq $dustbin} { + log "[string repeat " " $indent]Dustbin, skipping." 3 + incr indent -2 + return + } + + file stat "$dir/" st + + if {[specialdir $dir]} { + # Special folder + if {$st(dev) != $rootdev} { + log "[string repeat " " $indent\ + ]Special folder on different device, skipping." 3 + incr indent -2 + return + } + if {[llength $active]} { + set active {} + log "[string repeat " " $indent\ + ]Special folder, overriding recursion." 3 + } + } + + # Already seen + set key "$st(dev):$st(ino)" + if {$key in $seen} { + log "[string repeat " " $indent]Already seen, skipping." 3 + incr indent -2 + return + } + lappend seen $key + + set flags [lmap i \ + [glob -nocomplain -directory $dir -tails ".auto*"] \ + { string range $i 5 end }] + + foreach x $extraflags { + foreach f [lmap i \ + [glob -nocomplain -directory $dir -tails ".$x"] \ + { string range $i 1 end }] { + ladd flags $f + } + } + + foreach f $flags { + # If recursive flag found, add to active set. + if {[string index $f end] eq "R"} { + ladd active [string range $f 0 end-1] + } + } + + # Add any active flags to the set. + foreach f $active { + ladd flags $f + } + + if {[llength $flags]} { + lappend flagdb $dir $flags + log "[string repeat " " $indent] $flags" 3 + foreach f $flags { ladd activeflags $f } + } + + foreach entry [readdir -nocomplain $dir] { + if {[file isdirectory "$dir/$entry"]} { + buildflagdb "$dir/$entry" $active + } + } + + set active {} + + incr indent -2 +} + set ::auto::recalcdirs {} proc ::auto::recalcdir {dir} { @@ -124,120 +212,39 @@ proc ::auto::direntries {dir callback} { } } -proc ::auto::autoflagscan {dir attr callback {recurse 1} {force 0} {seen {}}} \ - {{indent 0} {forceflag ""}} { - variable dustbin - variable rootdev +proc ::auto::flagscan {root flag callback {recurse 1}} { + variable flagdb + variable activeflags - incr indent 2 - - log "[string repeat " " $indent]\[$dir]" 2 - - if {$dir eq $dustbin} { - log "[string repeat " " $indent]Dustbin, skipping." 2 - incr indent -2 + if {$flag ni $activeflags} { + log "No $flag flags in filesystem, suppressing scan." return } - file stat "$dir/" st - - if {[specialdir $dir]} { - # Special folder - if {$st(dev) != $rootdev} { - log "[string repeat " " $indent\ - ]Special folder on different device, skipping." 2 - incr indent -2 - return + if {!$recurse} { + # Just this exact directory + if {[dict exists $flagdb $root] && $flag in $flagdb($root)} { + log "[string toupper $flag]: \[$root]" 2 + $callback $root } - if {$force} { - set force 0 - set forceflag "" - log "[string repeat " " $indent\ - ]Special folder, overriding recursion." 2 - } - } - - # Already seen - set key "$st(dev):$st(ino)" - if {$key in $seen} { - log "[string repeat " " $indent]Already seen, skipping." 2 - incr indent -2 return } - lappend seen $key - # Recursion - if {!$force && [file exists "$dir/.auto${attr}r"]} { - log "[string repeat " " $indent] (R)" 2 - set force 1 - set forceflag "$dir/.auto${attr}r" - } + set rootl [string length $root] - oktorun - dsc - - if {$force || [file exists "$dir/.auto$attr"]} { - if {[$callback $dir] eq "STOP"} { - log "[string repeat " " $indent\ - ]Callback returned STOP." 2 - incr indent -2 - return "STOP" - } - } - - foreach entry [readdir -nocomplain $dir] { - if {$recurse && [file isdirectory "$dir/$entry"]} { - if {[autoflagscan "$dir/$entry" \ - $attr $callback $recurse $force \ - $seen] eq "STOP"} { - incr indent -2 - return "STOP" - } - file stat "$dir/$entry" st - set key "$st(dev):$st(ino)" - lappend seen $key - } - } - - incr indent -2 -} - -proc ::auto::flagscan {dir flag callback {seen {}}} { - variable dustbin - - if {$dir eq $dustbin} return - - if {[specialdir $dir]} return - - file stat $dir st - set key "$st(dev):$st(ino)" - if {$key in $seen} { - log "Already seen $dir ($key)" 2 - return - } - lappend seen $key - - if {[file exists "$dir/.$flag"]} { - if {[$callback $dir] eq "STOP"} { - log "Callback returned STOP." 2 - return "STOP" - } - } - - foreach entry [readdir -nocomplain $dir] { - if {[file isdirectory "$dir/$entry"]} { - if {[flagscan "$dir/$entry" $flag $callback $seen] - eq "STOP"} { - return "STOP" - } - - file stat "$dir/$entry" st - set key "$st(dev):$st(ino)" - lappend seen $key + foreach {dir flags} $flagdb { + if {![string equal -length $rootl $dir $root]} continue + if {$flag in $flags} { + oktorun + dsc + log "[string toupper $flag]: \[$dir]" 2 + if {[$callback $dir] eq "STOP"} break } } } +alias ::auto::autoflagscan ::auto::flagscan + ###################################################################### # Plugin registration @@ -251,6 +258,12 @@ proc ::auto::register {plugin {priority 500} {fn ""}} { log "Registered $plugin with priority $priority ($fn)" 2 } +proc ::auto::register_flag {plugin flag} { + variable extraflags + ladd extraflags $flag + log "Registered flag '$flag' for $plugin" 2 +} + # Backwards compatibility with legacy plugins set ::auto::legacy {} proc register {type fn {priority 50}} { @@ -312,6 +325,20 @@ if {[llength $::auto::legacy]} { alias scanup ::auto::autoflagscanup } +###################################################################### +# Run media flag database + +::auto::log "Scanning media for flags..." +set st [clock milliseconds] +::auto::buildflagdb $::auto::root +::auto::log "Scan completed ([::auto::elapsed $st] seconds)" +::auto::log "Active flags: $::auto::activeflags" +if {$::auto::loglevel > 1} { + foreach {dir flags} $::auto::flagdb { + ::auto::log "[format %-80s $dir] - $flags" 2 + } +} + ###################################################################### # Run plugins diff --git a/webif/lib/auto/upgrade b/webif/lib/auto/upgrade index e9941333..517d9dec 100755 --- a/webif/lib/auto/upgrade +++ b/webif/lib/auto/upgrade @@ -1,20 +1,55 @@ #!/mod/bin/jimsh source /mod/webif/lib/setup -require queue.class +require queue.class system.class -switch -- [queue version] { - 1 { - puts "Clearing queue due to version change..." - queue dbhandle -close - file delete /mod/etc/queue.db - queue dbhandle - } - 2 { - puts "Queue version is up-to-date." - } - default { - puts "Unknown queue version." +proc fixflags {dir} { + puts "Upgrading directory flags..." + foreach entry [readdir -nocomplain $dir] { + if {[file isdirectory "$dir/$entry"]} { + fixflags "$dir/$entry" + continue + } + if {[string match {.auto*r} $entry]} { + puts "Updating flag $dir/$entry" + file rename "$dir/$entry" \ + "$dir/[string range $entry 0 end-1]R" + } + } +} + +set queries { + 2 { {alter table queue add column last integer} } +} + +set latest 3 +set cur [queue version] + +if {$cur == $latest} { + puts "Queue database is up-to-date." + exit +} + +if {$cur < 3} { fixflags [system mediaroot] } + +if {$cur < 2} { + puts "Clearing queue due to version change..." + queue dbhandle -close + file delete /mod/etc/queue.db + queue dbhandle + set cur $latest +} + +set db [queue dbhandle] +loop i $cur $latest { + puts "Upgrading queue database to version $($i + 1)" + foreach q $queries($i) { + catch { $db query $q } + $db query { + update config + set val = %s + where var = 'version' + } $($i + 1) } } diff --git a/webif/lib/browse.class b/webif/lib/browse.class index bfcb1ca4..41a56e7f 100644 --- a/webif/lib/browse.class +++ b/webif/lib/browse.class @@ -36,7 +36,7 @@ proc {dir iconset} {dir} { set attrs {} set autoshrinkr 0 - if {[file exists "$dir/.autoshrinkr"]} { + if {[file exists "$dir/.autoshrinkR"]} { set autoshrinkr 1 lappend icons [_addicon "/img/compressr.png" \ "Recursive Auto-shrink"] @@ -58,7 +58,7 @@ proc {dir iconset} {dir} { } set autodecryptr 0 - if {[file exists "$dir/.autodecryptr"]} { + if {[file exists "$dir/.autodecryptR"]} { set autodecryptr 1 lappend icons [_addicon "/img/decryptr.png" \ "Recursive Auto-decrypt"] diff --git a/webif/lib/queue.class b/webif/lib/queue.class index 47e76bf8..bd06d355 100644 --- a/webif/lib/queue.class +++ b/webif/lib/queue.class @@ -14,6 +14,7 @@ class queue { retries 0 interrupts 0 submitted 0 + last 0 } # Queue status values: @@ -52,7 +53,8 @@ proc {queue dbhandle} {args} { runtime integer, retries integer default 0, interrupts integer default 0, - submitted integer + submitted integer, + last integer ); } $::queue::db query { @@ -62,7 +64,7 @@ proc {queue dbhandle} {args} { ); } $::queue::db query { - insert into config values('version', 2); + insert into config values('version', 3); } $::queue::db query { create unique index file on queue(file, action); @@ -117,13 +119,16 @@ proc {queue fetch} {file action} { return {} } -proc {queue insert} {ts action} { +proc {queue insert} {args ts action} { set db [queue dbhandle] + set status "PENDING" + if {"-hold" in $args} { set status "HOLD" } + $db query { - insert or ignore into queue(submitted, file, action) - values(%s, '%s', '%s') - } [clock seconds] [file normalize [$ts get file]] $action + insert or ignore into queue(submitted, file, action, status) + values(%s, '%s', '%s', '%s') + } [clock seconds] [file normalize [$ts get file]] $action $status return [queue fetch [$ts get file] $action] } @@ -259,9 +264,10 @@ queue method update {_status {_log ""} {_retries 0} {_runtime 0}} { set status = '%s', log = '%s', retries = retries + %s, - runtime = %s + runtime = %s, + last = %s where id = %s - } $_status $_log $_retries $_runtime $id + } $_status $_log $_retries $_runtime [clock seconds] $id set status $_status set log $_log @@ -279,3 +285,8 @@ queue method set {var val} { set $var $val } +queue method submit {{_start 0}} { + if {$_start} { $self set start $_start } + queue resubmit $id +} + diff --git a/webif/lib/rsv.class b/webif/lib/rsv.class index 3f35895e..cdc8177d 100755 --- a/webif/lib/rsv.class +++ b/webif/lib/rsv.class @@ -410,7 +410,7 @@ rsv method insert {{table pending} {force 0} {defer 0}} { } # Duplicate check - all tables - if {!$force && $action == 0} { + if {!$force && $action == 0 && $usevtid} { foreach tab {pending TBL_RESERVATION} { set rec [$rsvdb query " select ulslot from $tab diff --git a/webif/lib/tvdb.class b/webif/lib/tvdb.class index 2a98e3d4..da234e37 100644 --- a/webif/lib/tvdb.class +++ b/webif/lib/tvdb.class @@ -70,7 +70,7 @@ tvdb method _fetch {url} { return $ret } -tvdb method _parse {xml vars {end "XXX"}} { +tvdb method _parse {xml vars {end "XX"}} { set x [xml init $xml] set cattr 0 while {1} {