2013-02-27 23:15:37 +00:00
|
|
|
|
|
|
|
proc {file copy} {{force {}} source target} {
|
|
|
|
try {
|
|
|
|
if {$force ni {{} -force}} {
|
|
|
|
error "bad option \"$force\": should be -force"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![file exists $source]} {
|
|
|
|
error "source file does not exist."
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$force eq "" && [file exists $target]} {
|
|
|
|
error "error copying \"$source\" to \"$target\": file already exists"
|
|
|
|
}
|
|
|
|
exec /mod/bin/busybox/cp $source $target
|
|
|
|
} on error {msg opts} {
|
|
|
|
incr opts(-level)
|
|
|
|
return {*}$opts $msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {file rename} {{force {}} source target} {
|
|
|
|
try {
|
|
|
|
if {$force ni {{} -force}} {
|
|
|
|
error "bad option \"$force\": should be -force"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![file exists $source]} {
|
|
|
|
error "source file does not exist."
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$force eq "" && [file exists $target]} {
|
|
|
|
error "error copying \"$source\" to \"$target\": file already exists"
|
|
|
|
}
|
|
|
|
exec /mod/bin/busybox/mv $source $target
|
|
|
|
} on error {msg opts} {
|
|
|
|
incr opts(-level)
|
|
|
|
return {*}$opts $msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:51:10 +00:00
|
|
|
proc {file touch} {target {ref ""}} {
|
|
|
|
try {
|
|
|
|
if {$ref ne ""} {
|
|
|
|
if {![file exists $ref]} {
|
|
|
|
error "ref file does not exist."
|
|
|
|
}
|
|
|
|
exec /mod/bin/busybox/touch -r $ref $target
|
|
|
|
} else {
|
|
|
|
exec /mod/bin/busybox/touch $target
|
|
|
|
}
|
|
|
|
} on error {msg opts} {
|
|
|
|
incr opts(-level)
|
|
|
|
return {*}$opts $msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 23:15:37 +00:00
|
|
|
local proc file {cmd args} {
|
|
|
|
switch $cmd {
|
|
|
|
"rename" { tailcall {file rename} {*}$args }
|
|
|
|
"copy" { tailcall {file copy} {*}$args }
|
2013-10-29 20:51:10 +00:00
|
|
|
"touch" { tailcall {file touch} {*}$args }
|
2013-02-27 23:15:37 +00:00
|
|
|
default { tailcall upcall file $cmd {*}$args }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|