2013-01-30 23:48:37 +00:00
|
|
|
|
|
|
|
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 ""
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
proc _del_bindir {file {prefix ""}} {
|
2013-01-30 23:48:37 +00:00
|
|
|
global _del_dustbin
|
2013-02-25 22:31:54 +00:00
|
|
|
set lbin $_del_dustbin
|
|
|
|
if {$prefix ne ""} { append lbin "/$prefix" }
|
2013-01-30 23:48:37 +00:00
|
|
|
set dir [file dirname $file]
|
2013-02-25 22:31:54 +00:00
|
|
|
regsub "^[system mediaroot]" $dir $lbin ndir
|
|
|
|
if {$dir eq $ndir} { set ndir $lbin }
|
2013-01-30 23:48:37 +00:00
|
|
|
system mkdir_p $ndir
|
|
|
|
return $ndir
|
|
|
|
}
|
|
|
|
|
|
|
|
proc _del_touch {file} {
|
|
|
|
exec /mod/bin/busybox/touch $file
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
proc safe_delete {file {px ""}} {
|
2013-01-30 23:48:37 +00:00
|
|
|
global _del_dustbin
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
# Check if undelete is installed and that the file being
|
|
|
|
# deleted is not already in the dustbin.
|
|
|
|
set dustbin 1
|
|
|
|
if {$_del_dustbin eq "" || [\
|
2013-01-30 23:48:37 +00:00
|
|
|
string first $_del_dustbin $file] > -1} {
|
2013-02-25 22:31:54 +00:00
|
|
|
set dustbin 0
|
2013-01-30 23:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Directory
|
|
|
|
|
|
|
|
if {[file isdirectory $file]} {
|
2013-02-25 22:31:54 +00:00
|
|
|
if {$dustbin} {
|
|
|
|
set ndir "[_del_bindir $file $px]/[\
|
|
|
|
file tail $file]"
|
2013-01-30 23:48:37 +00:00
|
|
|
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}]} {
|
2013-02-25 22:31:54 +00:00
|
|
|
if {$dustbin} {
|
|
|
|
$ts move [_del_bindir $file $px] 1 1
|
2013-01-30 23:48:37 +00:00
|
|
|
} else {
|
|
|
|
if {[$ts delete]} {
|
|
|
|
return 1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# otherwise treat as normal file.
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
if {$dustbin} {
|
|
|
|
set nfile "[_del_bindir $file $px]/[file tail $file]"
|
2013-01-30 23:48:37 +00:00
|
|
|
file rename $file $nfile
|
|
|
|
_del_touch $nfile
|
|
|
|
} else {
|
|
|
|
tdelete $file
|
|
|
|
}
|
|
|
|
catch {file delete "[file rootname $file].hmi"}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|