From: Mark Wooding Date: Thu, 26 Mar 2015 02:09:27 +0000 (+0000) Subject: zoneconf.in: Split out the temporary-directory machinery. X-Git-Url: https://git.distorted.org.uk/~mdw/zoneconf/commitdiff_plain/07da6299118030363be4e6e19b199c7dba0abf1f?hp=15d2f3bd97a4fc41e1c74dd0af8c13dc7b2df16e zoneconf.in: Split out the temporary-directory machinery. Also, don't mention its name more than once. --- diff --git a/zoneconf.in b/zoneconf.in index 859fa67..137c2b5 100755 --- a/zoneconf.in +++ b/zoneconf.in @@ -1136,6 +1136,16 @@ proc output-file-name {view} { return [string map [list %v $view] $ZONECFG(conf-file)] } +proc temporary-directory {} { + ## Create a temporary directory and set as the working directory. + + global ZONECFG + set tmp [file join $ZONECFG(home-dir) "tmp"] + file mkdir $tmp + cd $tmp + return $tmp +} + proc compute-zone-properties {view config} { ## Derive interesting information from the zone configuration plist CONFIG, ## relative to the stated server VIEW. Return a new plist. @@ -1404,7 +1414,7 @@ provided by the named USER." isolate [list confspc-eval toplevel [list source $CONFFILE]] ## Make sure there's a temporary directory. - file mkdir [file join $ZONECFG(home-dir) "tmp"] + set tmpdir [temporary-directory] ## Keep track of cleanup jobs. set cleanup {} @@ -1435,8 +1445,7 @@ provided by the named USER." ## Make a new temporary file to read the zone into. set pid [pid] for {set i 0} {$i < 1000} {incr i} { - set tmp [file join $ZONECFG(home-dir) "tmp" \ - "tmp.$pid.$i.$user.$name"] + set tmp [file join $tmpdir "tmp.$pid.$i.$user.$name"] if {![catch { set chan [open $tmp {WRONLY CREAT EXCL}] } msg]} { break } elseif {[string equal [lindex $errorCode 0] POSIX] && \