From 08a1f092210455f8b98bbdb5643f5ef0a049037b Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 7 Jul 2014 22:06:04 +0000 Subject: [PATCH] add renamed file handling --- CONTROL/control | 2 +- webif/plugin/sweeper/auto.hook | 29 +++++++++++++++++++++++++++-- webif/plugin/sweeper/test | 3 ++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index cce5234..0a2d5e9 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -4,6 +4,6 @@ Section: misc Version: 2.0.7 Architecture: mipsel Maintainer: af123@hummypkg.org.uk -Depends: webif(>=1.0.15-5) +Depends: webif(>=1.0.15-7) Description: Sweeper is a package for managing recordings in a variety of ways using custom rules [See forum for details] Tags: http://hummy.tv/forum/threads/5138/ diff --git a/webif/plugin/sweeper/auto.hook b/webif/plugin/sweeper/auto.hook index 2a7281d..4b1015c 100644 --- a/webif/plugin/sweeper/auto.hook +++ b/webif/plugin/sweeper/auto.hook @@ -167,6 +167,9 @@ proc ::sweeper::moveset {ts dst {op rename}} { return } } + if {$op eq "rename"} { + set ::sweeper::renames($file) "$dst/[file tail $file]" + } return } @@ -192,6 +195,9 @@ proc ::sweeper::moveset {ts dst {op rename}} { return } } + if {$op eq "rename"} { + set ::sweeper::renames($file) "$dst/[file tail $file]" + } } # Search for a folder with name 'target' under 'root', skipping 'orig' @@ -428,7 +434,7 @@ proc ::sweeper::action_move {ts cmd arg folder} { ::sweeper::folder_apply [$ts dir] \ ::sweeper::action_move $ocmd $arg 0 if {$cmd eq "move"} { - ::sweeper::rmdir_if_empty $dir + ::sweeper::rmdir_if_empty [$ts dir] } return 1 } @@ -451,6 +457,9 @@ proc ::sweeper::action_move {ts cmd arg folder} { if {!$::sweeper::dryrun} { ::sweeper::moveset $ts $dir $cmd ::sweeper::qrecalc $dir [$ts dir] + if {$cmd eq "move"} { + ::sweeper::rmdir_if_empty [$ts dir] + } } return 1 } @@ -525,6 +534,7 @@ proc ::sweeper::action_renamefile {ts cmd arg folder} { ts renamegroup $file $arg if {[file exists "$dir/$arg.ts"]} { $ts setfile "$dir/$arg.ts" + set ::sweeper::renames($file) "$dir/$arg.ts" } else { log "... ERROR renamefile somehow failed" 0 } @@ -827,9 +837,24 @@ proc ::sweeper::sweep {dir} { ::sweeper::apply $dir "$dir/.sweeper" } -proc ::sweeper::scan {args} { +proc ::sweeper::scan {&files} { + log "::sweeper::scan files - ($files)" 2 + set ::sweeper::renames {} + ::sweeper::apply $::root $::sweeper::cf scan_run $::root sweeper ::sweeper::sweep + + log "::sweeper::scan renames - ($::sweeper::renames)" 2 + if {[llength $::sweeper::renames]} { + foreach k [array names ::sweeper::renames] { + set pos [lsearch $files $k] + log "$k = pos $pos" 2 + if {$pos == -1} continue + set files [lreplace $files $pos $pos \ + $::sweeper::renames($k)] + } + log "::sweeper::scan files - ($files)" 2 + } } if {[file exists $::sweeper::cf]} { diff --git a/webif/plugin/sweeper/test b/webif/plugin/sweeper/test index 8c4a863..c2a7659 100755 --- a/webif/plugin/sweeper/test +++ b/webif/plugin/sweeper/test @@ -3,7 +3,8 @@ source /mod/webif/plugin/sweeper/harness.jim if {![llength $argv]} { - ::sweeper::scan 0 + set files {} + ::sweeper::scan files } else { scan_run [lindex $argv 0] sweeper ::sweeper::sweep }