Author: dteske
Date: Thu Jul  4 20:12:12 2013
New Revision: 252721
URL: http://svnweb.freebsd.org/changeset/base/252721

Log:
  Implement $probe_only for the media access modules. sysinstall(8) was
  allowed to ignore the probe_only argument of its member functions solely
  because in the C language, the file accessor methods open and return a file
  descriptor and reading of the data is optional. In shell, the file accessor
  methods return data on stdout and that data should not be ignored (large
  files could block execution).
  
  So, we must adhere to the probe_only flags and in some cases (in the case of
  FTP, for example) change the `get' strategy to simply test existence and
  return an appropriate status.
  
  This was required because the up-coming package management stuff makes heavy
  use of the probe_only argument to try different package suffixes. Every
  media access module must implement $probe_only for the `get' accessor.

Modified:
  head/usr.sbin/bsdconfig/share/media/cdrom.subr
  head/usr.sbin/bsdconfig/share/media/common.subr
  head/usr.sbin/bsdconfig/share/media/directory.subr
  head/usr.sbin/bsdconfig/share/media/dos.subr
  head/usr.sbin/bsdconfig/share/media/floppy.subr
  head/usr.sbin/bsdconfig/share/media/ftp.subr
  head/usr.sbin/bsdconfig/share/media/nfs.subr
  head/usr.sbin/bsdconfig/share/media/ufs.subr
  head/usr.sbin/bsdconfig/share/media/usb.subr

Modified: head/usr.sbin/bsdconfig/share/media/cdrom.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/cdrom.subr      Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/cdrom.subr      Thu Jul  4 20:12:12 
2013        (r252721)
@@ -146,8 +146,8 @@ f_media_init_cdrom()
 
 # f_media_get_cdrom $device $file [$probe_only]
 #
-# Returns data from $file on a mounted CDROM device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# Returns data from $file on a mounted CDROM device. Similar to cat(1). If
+# $probe_only is present and non-NULL, returns success if $file exists.
 #
 f_media_get_cdrom()
 {
@@ -156,7 +156,7 @@ f_media_get_cdrom()
        f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_only=%s" \
                  "$dev" "$file" "$probe_only"
 
-       f_media_generic_get "$MOUNTPOINT" "$file"
+       f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
 }
 
 # f_media_shutdown_cdrom $device

Modified: head/usr.sbin/bsdconfig/share/media/common.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/common.subr     Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/common.subr     Thu Jul  4 20:12:12 
2013        (r252721)
@@ -83,16 +83,18 @@ f_media_verify()
        f_struct device_media || f_media_get_type
 }
 
-# f_media_generic_get $base $file
+# f_media_generic_get $base $file [$probe_only]
 #
-# A generic open which follows a well-known "path" of places to look.
+# A generic open which follows a well-known "path" of places to look. If
+# $probe_only is present and non-NULL, returns success if $file exists.
 # 
 f_media_generic_get()
 {
-       local base="$1" file="$2"
+       local base="$1" file="$2" probe_only="$3"
 
        local fname=f_media_generic_get
-       f_dprintf "%s: base=[%s] files=[%s]" $fname "$base" "$file"
+       f_dprintf "%s: base=[%s] files=[%s] probe_only=%s" \
+                 $fname "$base" "$file" "$probe_only"
 
        local rel path
        f_getvar $VAR_RELNAME rel
@@ -104,10 +106,19 @@ f_media_generic_get()
        ; do
                if [ -f "$path" -a -r "$path" ]; then
                        f_dprintf "%s: file exists path=[%s]" $fname "$path"
+                       [ "$probe_only" ] && return $SUCCESS
                        cat "$path"
                        return
                fi
        done
+
+       path="$base/releases/$rel/$file" # Final path to try
+       if [ -f "$path" -a -r "$path" ]; then
+               f_dprintf "%s: file exists path=[%s]" $fname "$path"
+               [ "$probe_only" ] && return $SUCCESS
+       elif [ "$probe_only" ]; then
+               return $FAILURE
+       fi
        cat "$base/releases/$rel/$file" # Final path to try
 }
 

Modified: head/usr.sbin/bsdconfig/share/media/directory.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/directory.subr  Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/directory.subr  Thu Jul  4 20:12:12 
2013        (r252721)
@@ -117,7 +117,8 @@ f_media_init_directory()
 # f_media_get_directory $device $file [$probe_only]
 #
 # Returns data from $file in the existing/current filesystem. Similar to
-# cat(1). $probe_only is currently unused by this media type.
+# cat(1). If $probe_only is present and non-NULL, returns success if $file
+# exists.
 #
 f_media_get_directory()
 {
@@ -127,7 +128,7 @@ f_media_get_directory()
                  "$dev" "$file" "$probe_only"
 
        device_$dev get private path
-       f_media_generic_get "$path" "$file"
+       f_media_generic_get "$path" "$file" "$probe_only"
 }
 
 # f_media_shutdown_directory $device

Modified: head/usr.sbin/bsdconfig/share/media/dos.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/dos.subr        Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/dos.subr        Thu Jul  4 20:12:12 
2013        (r252721)
@@ -125,7 +125,7 @@ f_media_init_dos()
 # f_media_get_dos $device $file [$probe_only]
 #
 # Returns data from $file on a mounted DOS partition device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_only is present and non-NULL, returns success if $file exists.
 #
 f_media_get_dos()
 {
@@ -134,7 +134,7 @@ f_media_get_dos()
        f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_only=%s" \
                  "$dev" "$file" "$probe_only"
 
-       f_media_generic_get "$MOUNTPOINT" "$file"
+       f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
 }
 
 # f_media_shutdown_dos $device

Modified: head/usr.sbin/bsdconfig/share/media/floppy.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/floppy.subr     Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/floppy.subr     Thu Jul  4 20:12:12 
2013        (r252721)
@@ -178,6 +178,8 @@ f_media_get_floppy()
                        f_media_init_floppy "$dev" || return $FAILURE
                        nretries=$(( $nretries - 1 ))
                done
+       elif [ "$probe_only" ]; then
+               return $SUCCESS
        fi
        cat "$fp"
 }

Modified: head/usr.sbin/bsdconfig/share/media/ftp.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/ftp.subr        Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/ftp.subr        Thu Jul  4 20:12:12 
2013        (r252721)
@@ -792,8 +792,8 @@ f_media_init_ftp()
 #
 # Returns data from $file on an FTP server using ftp(1). Please note that
 # $device is unused but must be present (even if null). Information is instead
-# gathered from the environment. $probe_only is currently unused by this media
-# type.
+# gathered from the environment. If $probe_only is present and non-NULL,
+# returns success if $file exists.
 #
 # Variables from variable.subr used to configure the connection are as follows
 # (all of which are configured by f_media_set_ftp above):
@@ -900,6 +900,17 @@ f_media_get_ftp()
 
        f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file";
 
+       if [ "$probe_only" ]; then
+               local url="ftp://$userpass$host$port/$dir/$file";
+               [ "$use_anon" ] && url="ftp://$host$port/$dir/$file";
+               if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
+               then
+                       f_dprintf "request failed! size response=[%s]" "$size"
+                       return $FAILURE
+               fi
+               return $SUCCESS
+       fi
+
        eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
             ftp -V ${use_anon:+-a} -o - \
                \"ftp://\$userpass\$host\$port/\$dir/\$file\"; 2> /dev/null

Modified: head/usr.sbin/bsdconfig/share/media/nfs.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/nfs.subr        Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/nfs.subr        Thu Jul  4 20:12:12 
2013        (r252721)
@@ -210,8 +210,8 @@ f_media_init_nfs()
 
 # f_media_get_nfs $device $file [$probe_only]
 #
-# Returns data from $file on a mounted NFS device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# Returns data from $file on a mounted NFS device. Similar to cat(1). If
+# $probe_only is present and non-NULL, returns success if $file exists.
 #
 f_media_get_nfs()
 {
@@ -220,7 +220,7 @@ f_media_get_nfs()
        f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_only=%s" \
                  "$dev" "$file" "$probe_only"
 
-       f_media_generic_get "$MOUNTPOINT" "$file"
+       f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
 }
 
 # f_media_shutdown_nfs $device

Modified: head/usr.sbin/bsdconfig/share/media/ufs.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/ufs.subr        Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/ufs.subr        Thu Jul  4 20:12:12 
2013        (r252721)
@@ -155,7 +155,7 @@ f_media_init_ufs()
 # f_media_get_ufs $device $file [$probe_only]
 #
 # Returns data from $file on a mounted UFS partition device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_only is present and non-NULL, returns success if $file exists.
 #
 f_media_get_ufs()
 {
@@ -164,7 +164,7 @@ f_media_get_ufs()
        f_dprintf "f_media_get_ufs: dev=[%s] file=[%s] probe_only=%s" \
                  "$dev" "$file" "$probe_only"
 
-       f_media_generic_get "$MOUNTPOINT" "$file"
+       f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
 }
 
 # f_media_shutdown_ufs $device

Modified: head/usr.sbin/bsdconfig/share/media/usb.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/usb.subr        Thu Jul  4 20:10:33 
2013        (r252720)
+++ head/usr.sbin/bsdconfig/share/media/usb.subr        Thu Jul  4 20:12:12 
2013        (r252721)
@@ -135,7 +135,7 @@ f_media_init_usb()
 # f_media_get_usb $device $file [$probe_only]
 #
 # Returns data from $file on a mounted USB disk device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_only is present and non-NULL, returns success if $file exists.
 #
 f_media_get_usb()
 {
@@ -144,7 +144,7 @@ f_media_get_usb()
        f_dprintf "f_media_get_usb: dev=[%s] file=[%s] probe_only=%s" \
                  "$dev" "$file" "$probe_only"
 
-       f_media_generic_get "$MOUNTPOINT" "$file"
+       f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
 }
 
 # f_media_shutdown_usb $device
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to