Skip to content
Permalink
Browse files

This is a basically rewritten port(1) contents target. Summary of cha…

…nges:

- Read the file in one line at a time, rather than all at once.
- Use regexp to match each line on {^contents \{(.*)\}$}, ensuring that only
the actual contents information will be matched.
- Move file-close check to the end of the target.
- Formatting fixes - stupid tabs!

These changes should be entirely transparent - it behaves exactly as it did
before.

Bug:            https://trac.macports.org/ticket/1252
Submitted by:   Toby Peterson <tp62@cornell.edu>

git-svn-id: https://svn.macports.org/repository/macports/trunk/base@4477 d073be05-634f-4543-b044-5fe20cf6d1d6
  • Loading branch information
Jordan K. Hubbard
Jordan K. Hubbard committed Jan 6, 2004
1 parent fc7fef5 commit d1c702cd37a7cfcde15fcea224dfd7d278d15091
Showing with 38 additions and 36 deletions.
  1. +38 −36 src/port/port.tcl
@@ -177,14 +177,14 @@ switch -- $action {

# make sure a port was given on the command line
if {![info exists portname]} {
puts "You must specify a port"
exit 1
puts "You must specify a port"
exit 1
}

# search for port
if {[catch {dportsearch ^$portname$} result]} {
puts "port search failed: $result"
exit 1
puts "port search failed: $result"
exit 1
}

if {$result == ""} {
@@ -235,27 +235,27 @@ switch -- $action {
variants {
# make sure a port was given on the command line
if {![info exists portname]} {
puts "You must specify a port"
exit 1
puts "You must specify a port"
exit 1
}

# search for port
if {[catch {dportsearch ^$portname$} result]} {
puts "port search failed: $result"
exit 1
puts "port search failed: $result"
exit 1
}

if {$result == ""} {
puts "No port $portname found."
}

array set portinfo [lindex $result 1]

# if this fails the port doesn't have any variants
if {![info exists portinfo(variants)]} {
puts "$portname has no variants"
} else {
# print out all the variants
# print out all the variants
for {set i 0} {$i < [llength $portinfo(variants)]} {incr i} {
puts "[lindex $portinfo(variants) $i]"
}
@@ -264,10 +264,10 @@ switch -- $action {
contents {
# make sure a port was given on the command line
if {![info exists portname]} {
puts "You must specify a port"
exit 1
puts "You must specify a port"
exit 1
}

set rfile [dportregistry::exists $portname]
if {$rfile != ""} {
if {[file extension $rfile] == ".bz2"} {
@@ -277,26 +277,28 @@ switch -- $action {
set shortname [file tail $rfile]
set fd [open $rfile r]
}
set entry [read $fd]
# kind of a corner case but I ran into it testing
if {[catch {close $fd} result]} {
puts "Port failed: $rfile may be corrupted"
exit 1
}

# look for a contents list
set ix [lsearch $entry contents]
if {$ix >= 0} {
set contents [lindex $entry [incr ix]]
set uninst_err 0
puts "Contents of $shortname"
foreach f $contents {
puts "\t[lindex $f 0]"

while {-1 < [gets $fd line]} {
set match [regexp {^contents \{(.*)\}$} $line dummy contents]
if {$match == 1} {
puts "Contents of $shortname"
foreach f $contents {
puts "\t[lindex $f 0]"
}
break
}
} else {
}

if {$match == 0} {
puts "No contents list for $shortname"
exit 1
}

# kind of a corner case but I ran into it testing
if {[catch {close $fd} result]} {
puts "Port failed: $rfile may be corrupted"
exit 1
}
} else {
puts "Contents listing failed - no registry entry"
exit 1
@@ -313,7 +315,7 @@ switch -- $action {
}
foreach {name array} $res {
array set portinfo $array

# XXX is this the right place to verify an entry?
if {![info exists portinfo(name)]} {
puts "Invalid port entry, missing portname"
@@ -350,8 +352,8 @@ switch -- $action {
default {
set target $action
if {[info exists portname]} {
# Escape regex special characters
regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $portname "\\\\&" search_string
# Escape regex special characters
regsub -all "(\\(){1}|(\\)){1}|(\\{1}){1}|(\\+){1}|(\\{1}){1}|(\\{){1}|(\\}){1}|(\\^){1}|(\\$){1}|(\\.){1}|(\\\\){1}" $portname "\\\\&" search_string
if {[catch {set res [dportsearch ^$search_string\$]} result]} {
puts "port search failed: $result"
exit 1
@@ -374,7 +376,7 @@ switch -- $action {
puts "Unable to execute port: $result"
exit 1
}

dportclose $workername
exit $result
}

0 comments on commit d1c702c

Please sign in to comment.
You can’t perform that action at this time.