Get rid of the legacy local variable got_it.
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Jul 12 19:52:09 2007 +0000 (2007-07-12)
changeset 2428e5b994260d0
parent 241 0aa95f4eed31
child 243 56fbb4be9521
Get rid of the legacy local variable got_it.
Allow to download files without extension.
Allow to specify a preffered extension when downloading a file.
scripts/functions
     1.1 --- a/scripts/functions	Thu Jul 12 19:20:36 2007 +0000
     1.2 +++ b/scripts/functions	Thu Jul 12 19:52:09 2007 +0000
     1.3 @@ -256,7 +256,6 @@
     1.4  CT_GetFileExtension() {
     1.5      local ext
     1.6      local file="$1"
     1.7 -    local got_it=1
     1.8  
     1.9      CT_Pushd "${CT_TARBALLS_DIR}"
    1.10      # we need to also check for an empty extension for those very
    1.11 @@ -265,7 +264,6 @@
    1.12      for ext in .tar.gz .tar.bz2 .tgz .tar ''; do
    1.13          if [ -f "${file}${ext}" ]; then
    1.14              echo "${ext}"
    1.15 -            got_it=0
    1.16              break
    1.17          fi
    1.18      done
    1.19 @@ -310,13 +308,19 @@
    1.20  }
    1.21  
    1.22  # Download the file from one of the URLs passed as argument
    1.23 -# Usage: CT_GetFile <filename> <url> [<url> ...]
    1.24 +# Usage: CT_GetFile <filename> [extension] <url> [url ...]
    1.25  CT_GetFile() {
    1.26 -    local got_it
    1.27      local ext
    1.28      local url
    1.29      local file="$1"
    1.30 +    local first_ext=""
    1.31      shift
    1.32 +    case "$1" in
    1.33 +        .tar.bz2|.tar.gz|.tgz|.tar)
    1.34 +            first_ext="$1"
    1.35 +            shift
    1.36 +            ;;
    1.37 +    esac
    1.38  
    1.39      # Do we already have it?
    1.40      ext=`CT_GetFileExtension "${file}"`
    1.41 @@ -326,11 +330,10 @@
    1.42      fi
    1.43  
    1.44      CT_Pushd "${CT_TARBALLS_DIR}"
    1.45 -    # File not yet downloaded, try to get it
    1.46 -    got_it=0
    1.47 -    # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar.
    1.48 +    # We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
    1.49 +    # or, as a failover, a file without extension.
    1.50      # Try local copy first, if it exists
    1.51 -    for ext in .tar.bz2 .tar.gz .tgz .tar; do
    1.52 +    for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
    1.53          if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
    1.54               "${CT_FORCE_DOWNLOAD}" != "y" ]; then
    1.55              CT_DoLog EXTRA "Copying \"${file}\" from local copy"
    1.56 @@ -340,7 +343,7 @@
    1.57      done
    1.58      # Try to download it
    1.59      CT_DoLog EXTRA "Retrieving \"${file}\""
    1.60 -    for ext in .tar.bz2 .tar.gz .tgz .tar; do
    1.61 +    for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
    1.62          # Try all urls in turn
    1.63          for url in "$@"; do
    1.64              case "${url}" in