util::archive_list_entries (private)
util::archive_list_entries -archive archive
Defined in packages/acs-tcl/tcl/utilities-procs.tcl
Return a list of entry names in the given archive. Supports: - ZIP-like archives (.zip, .jar, .war, .ear, .whl) - tar archives (.tar, .tar.gz, .tgz, .tar.bz2, .tar.xz) For other extensions, bsdtar is attempted if available.
- Switches:
- -archive (required)
- Testcases:
- No testcase defined.
Source code: set archive $archive set bsdtarCmd [util::which bsdtar] set unzipCmd [util::which unzip] set zipinfoCmd [util::which zipinfo] set tarCmd [util::which tar] set tail [string tolower [file tail $archive]] set ext [string tolower [file extension $tail]] # # Prefer bsdtar when available: it handles both tar and zip. # if {$bsdtarCmd ne ""} { if {[catch {exec -- $bsdtarCmd -tf $archive} out]} { error "Failed to list contents of archive '$archive' via bsdtar: $out" } set names {} foreach name [split $out "\n"] { set name [string trim $name] if {$name ne ""} { lappend names $name } } return $names } # # No bsdtar: use format-specific tools. # set zipExts {.zip .jar .war .ear .whl} set isZip [expr {$ext in $zipExts}] set isTar 0 if {!$isZip} { # Recognize common tar-style names. if {$ext eq ".tar"} { set isTar 1 } elseif {[string match "*.tar.gz" $tail] || [string match "*.tgz" $tail] || [string match "*.tar.bz2" $tail] || [string match "*.tar.xz" $tail]} { set isTar 1 } } if {$isZip} { # # ZIP-like: unzip -Z -1 or zipinfo -1 # if {$unzipCmd ne ""} { if {[catch {exec -- $unzipCmd -Z -1 $archive} out]} { error "Failed to list contents of zip archive '$archive' via unzip: $out" } set names {} foreach name [split $out "\n"] { set name [string trim $name] if {$name ne ""} { lappend names $name } } return $names } elseif {$zipinfoCmd ne ""} { if {[catch {exec -- $zipinfoCmd -1 $archive} out]} { error "Failed to list contents of zip archive '$archive' via zipinfo: $out" } set names {} foreach name [split $out "\n"] { set name [string trim $name] if {$name ne ""} { lappend names $name } } return $names } else { error "No suitable command (unzip/zipinfo/bsdtar) available to inspect zip archive '$archive'." } } if {$isTar} { # # tar archive: tar tf # if {$tarCmd eq ""} { error "No suitable command (tar/bsdtar) available to inspect tar archive '$archive'." } if {[catch {exec -- $tarCmd tf $archive} out]} { error "Failed to list contents of tar archive '$archive' via tar: $out" } set names {} foreach name [split $out "\n"] { set name [string trim $name] if {$name ne ""} { lappend names $name } } return $names } # # Unknown extension and no bsdtar: refuse, rather than guessing. # error "Unsupported archive type for '$archive' (no bsdtar and unrecognized extension)."XQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-tcl/tcl/utilities-procs.xql