forked from hummypkg/webif
safe delete library
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1381 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
parent
d2f61fb70e
commit
9d75b810c8
@ -1,7 +1,7 @@
|
||||
Package: webif
|
||||
Priority: optional
|
||||
Section: web
|
||||
Version: 0.11.0-3
|
||||
Version: 0.11.0-4
|
||||
Architecture: mipsel
|
||||
Maintainer: af123@hummypkg.org.uk
|
||||
Depends: webif-channelicons(>=1.0.4-1),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73-1),jim-cgi(>=0.6),jim-binary,service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.9-1),hmt(>=1.1.10),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2),smartmontools,tmenu(>=1.05)
|
||||
|
@ -25,5 +25,7 @@ grep -v 'backup/backup.jim' $ana > $tmpf
|
||||
|
||||
$PKG_ROOT/etc/init.d/S02anacron start < /dev/null > /dev/null 2>&1 &
|
||||
|
||||
[ -f /tmp/webif_auto.log ] && rm -f /tmp/webif_auto.log
|
||||
|
||||
exit 0
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package require cgi
|
||||
source /mod/webif/lib/setup
|
||||
require ts.class pretty_size system.class tdelete
|
||||
require safe_delete
|
||||
|
||||
puts "Content-Type: text/html\r\n"
|
||||
|
||||
@ -13,30 +13,10 @@ set dir [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 ndir
|
||||
if {$dir eq $ndir} { set ndir $dustbin }
|
||||
system mkdir_p $ndir
|
||||
return $ndir
|
||||
}
|
||||
|
||||
proc touch {file} {
|
||||
exec /mod/bin/busybox/touch $file
|
||||
}
|
||||
|
||||
puts "<div id=deleting class=blood><img src=/img/loading.gif>Deleting...</div>"
|
||||
puts "<ul style=\"list-style-type: square\">"
|
||||
|
||||
foreach file [cgi_get files] {
|
||||
|
||||
puts -nonewline "<li>\"$file\"..."
|
||||
|
||||
if {[string first "$dir/" $file] != 0} {
|
||||
@ -44,56 +24,10 @@ foreach file [cgi_get files] {
|
||||
continue
|
||||
}
|
||||
|
||||
if {$dustbin ne "" && [string first $dustbin $file] > -1} {
|
||||
set ldustbin ""
|
||||
if {[safe_delete $file]} {
|
||||
puts -nonewline "Done..."
|
||||
} else {
|
||||
set ldustbin $dustbin
|
||||
}
|
||||
|
||||
set done 0
|
||||
if {[file isdirectory $file]} {
|
||||
puts -nonewline "Directory..."
|
||||
if {$ldustbin ne ""} {
|
||||
set ndir "[bindir $file]/[file tail $file]"
|
||||
while {[file isdirectory $ndir]} {
|
||||
append ndir "_"
|
||||
}
|
||||
file rename $file $ndir
|
||||
touch $ndir
|
||||
} else {
|
||||
tdelete $file
|
||||
}
|
||||
puts -nonewline "Done..."
|
||||
set done 1
|
||||
} elseif {[string match {*.ts} $file]} {
|
||||
set ts [ts fetch $file]
|
||||
|
||||
# Check TS validity
|
||||
if {![catch {$ts get file}]} {
|
||||
if {$ldustbin ne ""} {
|
||||
$ts move [bindir $file] 1 1
|
||||
} else {
|
||||
if {[$ts delete]} {
|
||||
puts "Successfully deleted $file."
|
||||
} else {
|
||||
puts "Problem deleting $file, [$ts get error]"
|
||||
}
|
||||
}
|
||||
set done 1
|
||||
}
|
||||
# else treat as normal file.
|
||||
}
|
||||
|
||||
if {!$done} {
|
||||
if {$ldustbin ne ""} {
|
||||
set nfile "[bindir $file]/[file tail $file]"
|
||||
file rename $file $nfile
|
||||
touch $nfile
|
||||
} else {
|
||||
tdelete $file
|
||||
}
|
||||
catch {file delete "[file rootname $file].hmi"}
|
||||
puts -nonewline "Done..."
|
||||
puts -nonewline "Error..."
|
||||
}
|
||||
|
||||
puts "</li>"
|
||||
|
@ -325,7 +325,7 @@ proc scan {dir attr {force 0}} {{indent 0}} {
|
||||
|
||||
if {$force && [string match {\[*} [file tail $dir]]} {
|
||||
log "Special folder, skipping."
|
||||
return
|
||||
set force 0
|
||||
}
|
||||
|
||||
# Recursion
|
||||
|
85
var/mongoose/lib/safe_delete
Executable file
85
var/mongoose/lib/safe_delete
Executable file
@ -0,0 +1,85 @@
|
||||
|
||||
if {![exists -proc _del_bindir]} {
|
||||
|
||||
source /mod/webif/lib/setup
|
||||
require ts.class system.class tdelete
|
||||
|
||||
if {[system pkginst undelete]} {
|
||||
set _del_dustbin [system dustbin]
|
||||
} else {
|
||||
set _del_dustbin ""
|
||||
}
|
||||
|
||||
proc _del_bindir {file} {
|
||||
global _del_dustbin
|
||||
set dir [file dirname $file]
|
||||
regsub "^[system mediaroot]" $dir $_del_dustbin ndir
|
||||
if {$dir eq $ndir} { set ndir $_del_dustbin }
|
||||
system mkdir_p $ndir
|
||||
return $ndir
|
||||
}
|
||||
|
||||
proc _del_touch {file} {
|
||||
exec /mod/bin/busybox/touch $file
|
||||
}
|
||||
|
||||
proc safe_delete {file} {
|
||||
global _del_dustbin
|
||||
|
||||
# Check if the file is already in the dustbin
|
||||
|
||||
if {$_del_dustbin ne "" && [\
|
||||
string first $_del_dustbin $file] > -1} {
|
||||
set dustbin ""
|
||||
} else {
|
||||
set dustbin $_del_dustbin
|
||||
}
|
||||
|
||||
# Directory
|
||||
|
||||
if {[file isdirectory $file]} {
|
||||
if {$dustbin ne ""} {
|
||||
set ndir "[_del_bindir $file]/[file tail $file]"
|
||||
while {[file isdirectory $ndir]} {
|
||||
append ndir "_"
|
||||
}
|
||||
file rename $file $ndir
|
||||
_del_touch $ndir
|
||||
} else {
|
||||
tdelete $file
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
if {[string match {*.ts} $file]} {
|
||||
set ts [ts fetch $file]
|
||||
|
||||
# Check TS validity
|
||||
if {![catch {$ts get file}]} {
|
||||
if {$dustbin ne ""} {
|
||||
$ts move [_del_bindir $file] 1 1
|
||||
} else {
|
||||
if {[$ts delete]} {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
# otherwise treat as normal file.
|
||||
|
||||
if {$dustbin ne ""} {
|
||||
set nfile "[_del_bindir $file]/[file tail $file]"
|
||||
file rename $file $nfile
|
||||
_del_touch $nfile
|
||||
} else {
|
||||
tdelete $file
|
||||
}
|
||||
catch {file delete "[file rootname $file].hmi"}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user