[SM-Commit] BZR Change 23 to devel sorcery by Andrew Stitt <astitt at sourcemage.org>

bzr at mail.sourcemage.org bzr at mail.sourcemage.org
Sun Apr 23 20:50:03 EDT 2006


------------------------------------------------------------
revno: 23
committer: Andrew Stitt <astitt at sourcemage.org>
branch nick: devel-hack4
timestamp: Sun 2006-04-23 17:46:00 -0700
message:
  fix bug 9415, add some sanity checking to summon

=== modified file 'ChangeLog'
--- ChangeLog	
+++ ChangeLog	
@@ -1,3 +1,6 @@
+2006-04-23 Andrew Stitt <astitt at sourcemage.org>
+	* libsummon: fix bug 9415, do some sanity checking in summon
+
 2006-04-23 Andrew Stitt <astitt at sourcemage.org>
 	* dl_handlers/dl_svn: Do no interactive prompting
 

=== modified file 'var/lib/sorcery/modules/libsummon'
--- var/lib/sorcery/modules/libsummon	
+++ var/lib/sorcery/modules/libsummon	
@@ -239,9 +239,16 @@
     rm -rf $new_target
   elif [[ "$summon_type" == file ]] ; then
     # there is no penalty for guessing tree when the result is a file
-
     if [[ $summon_target != $target ]] ; then
-      mv -f $summon_target $target
+      mv -f "$summon_target" "$target"
+    fi
+    local type
+    if ! source_sanity "$target" "type"; then
+      message "${PROBLEM_COLOR}Sanity check of${DEFAULT_COLOR}" \
+              "${FILE_COLOR}${target}${DEFAULT_COLOR}" \
+              "${PROBLEM_COLOR}failed:${DEFAULT_COLOR}"
+      message "$type"
+      return 1
     fi
   else
     message "${PROBLEM_COLOR}Unknown download type: \"$summon_type\""\
@@ -406,6 +413,32 @@
   fi
   return 0
 }
+
+#---------------------------------------------------------------------
+## Perform rudimentary source sanity checks on summoned files.
+## Currently only checks that tarballs are not html 404 notices.
+## Some sites, notably sourceforge, break http by having missing files
+## do a 30X redirect to a 404 html file which when downloaded has a
+## 200 (OK) status. Other sites do 30X redirect to the new location of
+## the requested file, which then successfully downloads (which is
+## the correct thing to do). We catch that here rather than wait for
+## file verification to catch it.
+#---------------------------------------------------------------------
+function source_sanity() {
+  [[ "$1" ]] && return 0
+  [[ "$SUMMON_SANITY" == off ]] && return 0
+  if [[ "$1" != "${1%.tar.bz2}" ]] ||
+     [[ "$1" != "${1%.tar.gz}" ]] ||
+     [[ "$1" != "${1%.tgz}" ]]; then
+    local _type=$(file "$1")
+    if echo $_type | grep -iq HTML ||
+       echo $_type | grep -iq ascii ; then
+      upvar "$2" "$_type"
+      return 1
+    fi
+  fi
+
+}
 #---------------------------------------------------------------------
 ## This software is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by




More information about the SM-Commit mailing list