Ignore:
Timestamp:
Sep 28, 2003, 8:55:11 PM (15 years ago)
Author:
landonf
Message:

Fixed two issues in reinplace:
Use mkstemp, not mktemp
File attributes are preserved

File:
1 edited

Legend:

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

    r3410 r3560  
    383383
    384384    foreach file $args {
    385         if {[catch {set tmpfile [mktemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
     385        if {[catch {set tmpfile [mkstemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
    386386            ui_error "reinplace: $error"
    387387            return -code error "reinplace failed"
    388         }
    389 
    390         if {[catch {exec sed $pattern < $file > $tmpfile} error]} {
     388        } else {
     389            # Extract the Tcl Channel number
     390            set tmpfd [lindex $tmpfile 0]
     391            # Set tmpfile to only the file name
     392            set tmpfile [lindex $tmpfile 1]
     393        }
     394
     395        if {[catch {exec sed $pattern < $file >@ $tmpfd} error]} {
    391396            ui_error "reinplace: $error"
    392397            file delete "$tmpfile"
     
    394399        }
    395400
    396         if {[catch {file attributes $file -permissions +w} error]} {
     401        close $tmpfd
     402
     403        set attributes [file attributes $file]
     404        # We need to overwrite this file
     405        if {[catch {file attributes $file -permissions u+w} error]} {
    397406            ui_error "reinplace: $error"
    398407            file delete "$tmpfile"
     
    405414            return -code error "reinplace failed"
    406415        }
     416       
     417        for {set i 0} {$i < [llength attributes]} {incr i} {
     418            set opt [lindex $attributes $i]
     419            incr i
     420            set arg [lindex $attributes $i]
     421            file attributes $file $opt $arg
     422        }
     423       
    407424        file delete "$tmpfile"
    408425    }
Note: See TracChangeset for help on using the changeset viewer.