diff options
author | dteske <dteske@FreeBSD.org> | 2013-07-04 20:12:12 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-07-04 20:12:12 +0000 |
commit | d22cbd9996dd8eeb66460e624d65b8abd94f8c4e (patch) | |
tree | ed5346e9e8f574fef1a7c5c9b6c87afd2fff418f /usr.sbin/bsdconfig/share | |
parent | eeea14c75af862477741d779b12b307abdd49fbc (diff) | |
download | FreeBSD-src-d22cbd9996dd8eeb66460e624d65b8abd94f8c4e.zip FreeBSD-src-d22cbd9996dd8eeb66460e624d65b8abd94f8c4e.tar.gz |
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.
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r-- | usr.sbin/bsdconfig/share/media/cdrom.subr | 6 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/common.subr | 19 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/directory.subr | 5 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/dos.subr | 4 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/floppy.subr | 2 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/ftp.subr | 15 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/nfs.subr | 6 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/ufs.subr | 4 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/media/usb.subr | 4 |
9 files changed, 45 insertions, 20 deletions
diff --git a/usr.sbin/bsdconfig/share/media/cdrom.subr b/usr.sbin/bsdconfig/share/media/cdrom.subr index 6f7afcd..4350367 100644 --- a/usr.sbin/bsdconfig/share/media/cdrom.subr +++ b/usr.sbin/bsdconfig/share/media/cdrom.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/common.subr b/usr.sbin/bsdconfig/share/media/common.subr index 581e501..4550d70 100644 --- a/usr.sbin/bsdconfig/share/media/common.subr +++ b/usr.sbin/bsdconfig/share/media/common.subr @@ -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 } diff --git a/usr.sbin/bsdconfig/share/media/directory.subr b/usr.sbin/bsdconfig/share/media/directory.subr index cd0fd41..9a7e66c 100644 --- a/usr.sbin/bsdconfig/share/media/directory.subr +++ b/usr.sbin/bsdconfig/share/media/directory.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/dos.subr b/usr.sbin/bsdconfig/share/media/dos.subr index ab15097..9320c2c 100644 --- a/usr.sbin/bsdconfig/share/media/dos.subr +++ b/usr.sbin/bsdconfig/share/media/dos.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/floppy.subr b/usr.sbin/bsdconfig/share/media/floppy.subr index bb78518..beb574e 100644 --- a/usr.sbin/bsdconfig/share/media/floppy.subr +++ b/usr.sbin/bsdconfig/share/media/floppy.subr @@ -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" } diff --git a/usr.sbin/bsdconfig/share/media/ftp.subr b/usr.sbin/bsdconfig/share/media/ftp.subr index c2c7e6a..fb96b91 100644 --- a/usr.sbin/bsdconfig/share/media/ftp.subr +++ b/usr.sbin/bsdconfig/share/media/ftp.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/nfs.subr b/usr.sbin/bsdconfig/share/media/nfs.subr index b1dad4f..86bdde2 100644 --- a/usr.sbin/bsdconfig/share/media/nfs.subr +++ b/usr.sbin/bsdconfig/share/media/nfs.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/ufs.subr b/usr.sbin/bsdconfig/share/media/ufs.subr index 5a4113e..14e2081 100644 --- a/usr.sbin/bsdconfig/share/media/ufs.subr +++ b/usr.sbin/bsdconfig/share/media/ufs.subr @@ -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 diff --git a/usr.sbin/bsdconfig/share/media/usb.subr b/usr.sbin/bsdconfig/share/media/usb.subr index 4117e51..c2ece47 100644 --- a/usr.sbin/bsdconfig/share/media/usb.subr +++ b/usr.sbin/bsdconfig/share/media/usb.subr @@ -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 |