<pre style='margin:0'>
Rainer Müller (raimue) pushed a commit to branch vcs-fetch
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/2c216c7ee45f0372e80d3c36faf074b0fb4f1e5c">https://github.com/macports/macports-base/commit/2c216c7ee45f0372e80d3c36faf074b0fb4f1e5c</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 2c216c7ee45f0372e80d3c36faf074b0fb4f1e5c
</span>Author: Rainer Müller <raimue@macports.org>
AuthorDate: Mon Apr 2 03:46:28 2018 +0200
<span style='display:block; white-space:pre;color:#404040;'> fetch: Ensure mktar does not leak temporary files
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Wrap mktar in a try/catch block to always delete the incomplete output
</span><span style='display:block; white-space:pre;color:#404040;'> files in case of an error or an interrupt.
</span>---
src/port1.0/portfetch.tcl | 84 +++++++++++++++++++++++++----------------------
1 file changed, 44 insertions(+), 40 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/port1.0/portfetch.tcl b/src/port1.0/portfetch.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index a20bf0b..84fde4e 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/port1.0/portfetch.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/port1.0/portfetch.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -327,54 +327,58 @@ proc compressfile {file} {
</span> proc portfetch::mktar {tarfile dir mtime {excludes {}}} {
set mtreefile "${tarfile}.mtree"
<span style='display:block; white-space:pre;background:#ffe0e0;'>- # write the list of files in sorted order to mtree file with the
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # permissions and ownership we want
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set mtreefd [open $mtreefile w]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- puts $mtreefd "#mtree"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- puts $mtreefd "/set uname=root uid=0 gname=root gid=0 time=$mtime"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- fs-traverse -tails -exclude $excludes f $dir {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set fpath [file join $dir $f]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {$f ne "."} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # map type from Tcl to mtree
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set type [file type $fpath]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- array set typemap {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- file file
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- directory dir
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- characterSpecial char
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- blockSpecial block
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- fifo fifo
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- link link
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- socket socket
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # not try -pass_signal, we want to catch interrupts
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # write the list of files in sorted order to mtree file with the
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # permissions and ownership we want
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set mtreefd [open $mtreefile w]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts $mtreefd "#mtree"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts $mtreefd "/set uname=root uid=0 gname=root gid=0 time=$mtime"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fs-traverse -tails -exclude $excludes f $dir {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set fpath [file join $dir $f]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$f ne "."} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # map type from Tcl to mtree
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set type [file type $fpath]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ array set typemap {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ file file
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ directory dir
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ characterSpecial char
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ blockSpecial block
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fifo fifo
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ link link
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ socket socket
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![info exists typemap($type)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ error "unknown file type $type"
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists typemap($type)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -code error "unknown file type $type"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set type $typemap($type)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set type $typemap($type)
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {$type eq "link"} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set mode 0777
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- # use user permissions only, ignore the rest
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set mode [format "%o" [expr [file attributes $fpath -permissions] & 0700]]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$type eq "link"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set mode 0777
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # use user permissions only, ignore the rest
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set mode [format "%o" [expr [file attributes $fpath -permissions] & 0700]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- # add entry to mtree output
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- puts $mtreefd "$f type=$type mode=$mode"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # add entry to mtree output
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts $mtreefd "$f type=$type mode=$mode"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- close $mtreefd
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ close $mtreefd
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- # TODO: add dependency on libarchive, if /usr/bin/tar is not bsdtar
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set tar [findBinary bsdtar tar]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set cmdstring "${tar} -cf $tarfile @$mtreefile 2>&1"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if {[catch {system -W $dir $cmdstring} result]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- delete $mtreefile
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # TODO: add dependency on libarchive, if /usr/bin/tar is not bsdtar
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set tar [findBinary bsdtar tar]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set cmdstring "${tar} -cf $tarfile @$mtreefile 2>&1"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[catch {system -W $dir $cmdstring} result]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ error [msgcat::mc "tarball creation failed"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } catch {{*} eCode eMessage} {
</span> delete $tarfile
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return -code error [msgcat::mc "tarball creation failed"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ throw
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } finally {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ delete $mtreefile
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- delete $mtreefile
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> return 0
}
</pre><pre style='margin:0'>
</pre>