summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share/media/ftp.subr
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-07-14 03:08:52 +0000
committerdteske <dteske@FreeBSD.org>2013-07-14 03:08:52 +0000
commite9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a (patch)
treea9511d0f643be26ac006b8084db35a955fc813f9 /usr.sbin/bsdconfig/share/media/ftp.subr
parentc6eaf899761fc14eab6497d13c5ac87c11300777 (diff)
downloadFreeBSD-src-e9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a.zip
FreeBSD-src-e9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a.tar.gz
Re-implement $probe_only aspect of f_media_get_TYPE() (where TYPE is cdrom,
nfs, ftp, http, httpproxy, etc.) and f_device_get() (abstract method for calling aforementioned f_media_get_TYPE()). Previously, if $probe_only was present and non-NULL, the TYPE functions would check for $file and exit with an appropriate error status (success if the file exists and readable, failure otherwise). While this has been retained, a pair of globals has been introduced: $PROBE_EXIST and $PROBE_SIZE (see `/usr/share/bsdconfig/media/common.subr') The $PROBE_EXIST global can be used where you need the functionality of simply testing for existence (previously the _only_ functionality). Meanwhile, the new $PROBE_SIZE global can be used to cause the TYPE function to print the size of the file (in bytes) on standard-out (or -1) if not found or an error occurs. NOTE: If an error occurs, it is logged with the dprintf function, which is visible with `-d' flag or debug=1. In many cases, where you need to get the size of a file _and_ check for its existence, you can use the return status of a $PROBE_SIZE call.
Diffstat (limited to 'usr.sbin/bsdconfig/share/media/ftp.subr')
-rw-r--r--usr.sbin/bsdconfig/share/media/ftp.subr19
1 files changed, 11 insertions, 8 deletions
diff --git a/usr.sbin/bsdconfig/share/media/ftp.subr b/usr.sbin/bsdconfig/share/media/ftp.subr
index ac46a27..638584c 100644
--- a/usr.sbin/bsdconfig/share/media/ftp.subr
+++ b/usr.sbin/bsdconfig/share/media/ftp.subr
@@ -787,12 +787,13 @@ f_media_init_ftp()
return $FAILURE
}
-# f_media_get_ftp $device $file [$probe_only]
+# f_media_get_ftp $device $file [$probe_type]
#
# 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. If $probe_only is present and non-NULL,
-# returns success if $file exists.
+# gathered from the environment. If $probe_type is present and non-NULL,
+# returns success if $file exists. If $probe_type is equal to $PROBE_SIZE,
+# prints the size of $file in bytes to standard-out.
#
# Variables from variable.subr used to configure the connection are as follows
# (all of which are configured by f_media_set_ftp above):
@@ -826,10 +827,10 @@ f_media_init_ftp()
#
f_media_get_ftp()
{
- local dev="$1" file="$2" probe_only="$3" hosts=
+ local dev="$1" file="$2" probe_type="$3" hosts=
- f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
local ftp_host ftp_port
f_getvar $VAR_FTP_HOST ftp_host
@@ -899,14 +900,16 @@ 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"
+ if [ "$probe_type" ]; then
+ local url="ftp://$userpass$host$port/$dir/$file" size
[ "$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"
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
return $FAILURE
fi
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "$size"
return $SUCCESS
fi
OpenPOWER on IntegriCloud