Ignore:
Timestamp:
Oct 13, 2002, 4:43:25 AM (16 years ago)
Author:
jkh
Message:

Add an mktemp primitive for simply getting a convenient temporary file
handle (mkstemp left alone since it provides file handles atomically and
cannot simply be simulated by a Tcl procedure returning [open mktemp $arg]).

Make reinplace use this to provide far simpler and less error prone operation.

Remove the ftruncate primitive since it was provided solely to work around
a problem in reinplace.

File:
1 edited

Legend:

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

    r1033 r1045  
    303303    set pattern [strsed $backpattern {g/\|/\//}]
    304304
    305     if {[catch {set input [open "$file" RDWR]} error]} {
     305    if {[catch {set tmpfile [mktemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
    306306        ui_error "reinplace: $error"
    307307        return -code error "reinplace failed"
    308308    }
    309309
    310     if {[catch {set result [mkstemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
     310    if {[catch {exec sed $pattern < $file > $tmpfile} error]} {
    311311        ui_error "reinplace: $error"
    312         close $input
    313         return -code error "reinplace failed"
    314     }
    315 
    316     set output [lindex $result 0]
    317     set tmpfile [lindex $result 1]
    318 
    319     if {[catch {exec sed $pattern <@$input >@$output} error]} {
    320         ui_error "reinplace: $error"
    321         close $output
    322         close $input
    323312        file delete "$tmpfile"
    324313        return -code error "reinplace failed"
    325314    }
    326315
    327     seek $output 0
    328     seek $input 0
    329 
    330     # copy from strsed output back into the input
    331     if {[catch {fcopy $output $input} error]} {
     316    if {[catch {exec cp $tmpfile $file} error]} {
    332317        ui_error "reinplace: $error"
    333         close $output
    334         close $input
    335318        file delete "$tmpfile"
    336319        return -code error "reinplace failed"
    337320    }
    338        
    339     set eof [file size "$tmpfile"]
    340     ftruncate $input $eof
    341 
    342     close $output
    343     close $input
    344321    file delete "$tmpfile"
    345322    return
Note: See TracChangeset for help on using the changeset viewer.