Ignore:
Timestamp:
Apr 24, 2007, 10:23:05 AM (11 years ago)
Author:
eridius@…
Message:

Reimplement delete using fs-traverse - *much* smaller now.
Add test file for portutil, currently only tests delete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portutil.tcl

    r24199 r24435  
    712712# delete
    713713# file delete -force by itself doesn't handle directories properly
    714 # on systems older than Tiger. However we can recurse this thing ourselves
     714# on systems older than Tiger. Lets recurse using fs-traverse instead
    715715proc delete {args} {
    716     foreach arg $args {
    717         ui_debug "delete: $arg"
    718         set stack [list $arg]
    719         while {[llength $stack] > 0} {
    720             set file [lindex $stack 0]
    721             if {[string equal [file type $file] directory]} {
    722                 # it's a directory
    723                 set children [glob -nocomplain -directory $file * .*]
    724                 set children [ldelete [ldelete $children $file/.] $file/..]
    725                 if {[llength $children] > 0} {
    726                     set stack [concat $children $stack]
    727                 } else {
    728                     # directory is empty
    729                     file delete -force -- $file
    730                     set stack [lrange $stack 1 end]
    731                 }
    732             } else {
    733                 # it's not a directory - kill it now
    734                 file delete -force -- $file
    735                 set stack [lrange $stack 1 end]
    736             }
    737         }
     716    ui_debug "delete: $args"
     717    fs-traverse -depth file $args {
     718        file delete -force -- $file
     719        continue
    738720    }
    739721}
Note: See TracChangeset for help on using the changeset viewer.