forked from hummypkg/webif
22320536ee
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1420 2a923420-c742-0410-a762-8d5b09965624
88 lines
1.7 KiB
Plaintext
Executable File
88 lines
1.7 KiB
Plaintext
Executable File
|
|
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 {prefix ""}} {
|
|
global _del_dustbin
|
|
set lbin $_del_dustbin
|
|
if {$prefix ne ""} { append lbin "/$prefix" }
|
|
set dir [file dirname $file]
|
|
regsub "^[system mediaroot]" $dir $lbin ndir
|
|
if {$dir eq $ndir} { set ndir $lbin }
|
|
system mkdir_p $ndir
|
|
return $ndir
|
|
}
|
|
|
|
proc _del_touch {file} {
|
|
exec /mod/bin/busybox/touch $file
|
|
}
|
|
|
|
proc safe_delete {file {px ""}} {
|
|
global _del_dustbin
|
|
|
|
# Check if undelete is installed and that the file being
|
|
# deleted is not already in the dustbin.
|
|
set dustbin 1
|
|
if {$_del_dustbin eq "" || [\
|
|
string first $_del_dustbin $file] > -1} {
|
|
set dustbin 0
|
|
}
|
|
|
|
# Directory
|
|
|
|
if {[file isdirectory $file]} {
|
|
if {$dustbin} {
|
|
set ndir "[_del_bindir $file $px]/[\
|
|
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} {
|
|
$ts move [_del_bindir $file $px] 1 1
|
|
} else {
|
|
if {[$ts delete]} {
|
|
return 1
|
|
} else {
|
|
return 0
|
|
}
|
|
}
|
|
return 1
|
|
}
|
|
}
|
|
|
|
# otherwise treat as normal file.
|
|
|
|
if {$dustbin} {
|
|
set nfile "[_del_bindir $file $px]/[file tail $file]"
|
|
file rename $file $nfile
|
|
_del_touch $nfile
|
|
} else {
|
|
tdelete $file
|
|
}
|
|
catch {file delete "[file rootname $file].hmi"}
|
|
return 1
|
|
}
|
|
}
|
|
|