From 6e2a0f3e2b637c1bb8c92be09a93269a0a226c8b Mon Sep 17 00:00:00 2001 From: hummypkg Date: Tue, 10 Jan 2012 19:51:45 +0000 Subject: [PATCH] dustbin support + bugfix git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@648 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- var/mongoose/cgi-bin/backup/restore.jim | 2 +- var/mongoose/cgi-bin/browse/clipboard.jim | 48 +++++++++++------------ var/mongoose/cgi-bin/browse/delete.jim | 44 +++++++++++++++++---- var/mongoose/cgi-bin/browse/mdelete.jim | 43 +++++++++++++++----- var/mongoose/lib/system.class | 12 ++++++ var/mongoose/lib/ts.class | 26 +++++++++++- 7 files changed, 133 insertions(+), 44 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index 7aebf04..e0433be 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 0.8.11 +Version: 0.8.11-1 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: mongoose(>=3.0-2),jim(>=0.71-1),jim-sqlite3(>=0.71-1),jim-cgi(>=0.5),jim-oo,jim-pack,service-control,busybox(>=1.19.3-1),lsof,epg(>=1.0.8),hmt(>=1.1.4),ssmtp,anacron diff --git a/var/mongoose/cgi-bin/backup/restore.jim b/var/mongoose/cgi-bin/backup/restore.jim index 67c845c..5b01a43 100755 --- a/var/mongoose/cgi-bin/backup/restore.jim +++ b/var/mongoose/cgi-bin/backup/restore.jim @@ -106,7 +106,7 @@ foreach line $data { puts " $chan" - if {!$hsvc} { + if {$hsvc eq ""} { puts " Cannot map channel name to service." continue } diff --git a/var/mongoose/cgi-bin/browse/clipboard.jim b/var/mongoose/cgi-bin/browse/clipboard.jim index 50b735b..70d772c 100755 --- a/var/mongoose/cgi-bin/browse/clipboard.jim +++ b/var/mongoose/cgi-bin/browse/clipboard.jim @@ -2,9 +2,12 @@ package require cgi source /mod/var/mongoose/lib/setup -require clipboard.class ts.class chunked +require clipboard.class ts.class -start_chunked "text/html; no-cache\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\nPragma: nocache" +puts "Content-Type: text/html; no-cache" +puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT" +puts "Pragma: nocache" +puts "" cgi_input 1 #cgi_dump @@ -16,10 +19,10 @@ set action [cgi_get act list] switch $action { list { if {![$cb size]} { - chunk "Clipboard is empty" + puts "Clipboard is empty" break } - chunk "
" + puts "
" foreach file [$cb get items] { set img "page_white_copy" if {[$file get action] eq "cut"} { @@ -27,28 +30,28 @@ switch $action { } set path [$file get path] set xpath [cgi_quote_html $path] - chunk "" - chunk "" + puts "" + puts "" set dfile [file tail $path] if {[string length $dfile] > 25} { set dfile "[string range $dfile 0 22]..." } if {[file isdirectory $path]} { - chunk "" } - chunk [cgi_quote_html $dfile] - chunk " " - chunk "" + puts "" } - chunk "
" - chunk "" + puts "
" + puts "" } add { if {[set path [cgi_get path]] eq "0"} { - chunk "No path." + puts "No path." exit } set dir [cgi_unquote_input [cgi_get dir]] @@ -56,12 +59,12 @@ switch $action { foreach p $path { set p [cgi_unquote_input $p] if {$dir ne "0" && ![string match "$dir/*" $p]} { - chunk "$p not in directory
" + puts "$p not in directory
" continue } if {![$cb present $p]} { $cb add $mode $p - chunk "Added $p for $mode
" + puts "Added $p for $mode
" } } $cb save @@ -81,16 +84,15 @@ switch $action { set file [file tail $path] set mode [$item get action] - chunk "Pasting $file" - chunk_pad + puts "Pasting $file" if {[file isdirectory $path]} { # Directory if {$mode eq "cut"} { - file rename $path "$dir/$file" + catch {file rename $path "$dir/$file"} } else { - chunk [exec /mod/bin/busybox/cp -r \ - $path $dir] + catch {puts [exec /mod/bin/busybox/cp -r \ + $path $dir]} } } else { set root [file rootname $path] @@ -100,9 +102,9 @@ switch $action { regsub -all {([\\["$])} $root {\\\1} root foreach f [glob -nocomplain "${root}.*"] { if {$mode eq "cut"} { - file rename $f "$dir/[file tail $f]" + catch {file rename $f "$dir/[file tail $f]"} } else { - file copy $f "$dir/[file tail $f]" + catch {file copy $f "$dir/[file tail $f]"} } } } @@ -112,5 +114,3 @@ switch $action { } } -end_chunked - diff --git a/var/mongoose/cgi-bin/browse/delete.jim b/var/mongoose/cgi-bin/browse/delete.jim index c5538e4..4387b84 100755 --- a/var/mongoose/cgi-bin/browse/delete.jim +++ b/var/mongoose/cgi-bin/browse/delete.jim @@ -1,7 +1,8 @@ #!/mod/bin/jimsh package require cgi -source /mod/var/mongoose/lib/ts.class +source /mod/var/mongoose/lib/setup +require ts.class system.class puts "Content-Type: text/html" puts "" @@ -12,21 +13,50 @@ cgi_input set file [dict get $_cgi file] set type [dict get $_cgi type] +if {[system pkginst undelete]} { + set dustbin [system dustbin] +} else { + set dustbin "" +} + +proc bindir {file} { + global dustbin + set dir [file dirname $file] + regsub "^[system mediaroot]" $dir $dustbin dir + system mkdir_p $dir + return $dir +} + if {$type eq "ts"} { set ts [ts fetch $file] - if {[$ts delete]} { - puts "Successfully deleted $file." + if {$dustbin ne ""} { + $ts move [bindir $file] } else { - puts "Problem deleting $file, [$ts get error]" + if {[$ts delete]} { + puts "Successfully deleted $file." + } else { + puts "Problem deleting $file, [$ts get error]" + } } exit } elseif {$type eq "dir"} { puts -nonewline "Directory..." - puts [exec /mod/bin/busybox/rm -rf $file] + if {$dustbin ne ""} { + set ndir "[bindir $file]/[file tail $file]" + while {[file isdirectory $ndir]} { append ndir "_" } + file rename $file $ndir + } else { + puts [exec /mod/bin/busybox/rm -rf $file] + } puts -nonewline "Done..." } else { - file delete $file - file delete "[file rootname $file].hmi" + if {$dustbin ne ""} { + file rename $file "[bindir $file]/[file tail $file]" + } else { + file delete $file + } + catch {file delete "[file rootname $file].hmi"} + puts "Successfully deleted $file." } diff --git a/var/mongoose/cgi-bin/browse/mdelete.jim b/var/mongoose/cgi-bin/browse/mdelete.jim index f5cae31..845a0ae 100755 --- a/var/mongoose/cgi-bin/browse/mdelete.jim +++ b/var/mongoose/cgi-bin/browse/mdelete.jim @@ -2,7 +2,7 @@ package require cgi source /mod/var/mongoose/lib/setup -require ts.class pretty_size +require ts.class pretty_size system.class puts "Content-Type: text/html\r\n\r\n" @@ -13,6 +13,20 @@ set dir [cgi_unquote_input [cgi_get dir]] #puts "DIR: ($dir)" +if {[system pkginst undelete]} { + set dustbin [system dustbin] +} else { + set dustbin "" +} + +proc bindir {file} { + global dustbin + set dir [file dirname $file] + regsub "^[system mediaroot]" $dir $dustbin dir + system mkdir_p $dir + return $dir +} + puts "
Deleting...
" puts "