16419678 pkg/mirror should empty its cache on success
16427874 pkg/mirror should set the default publisher if not already set
--- a/src/svc/svc-pkg-mirror Fri Mar 01 14:17:24 2013 -0800
+++ b/src/svc/svc-pkg-mirror Wed Mar 06 10:22:53 2013 +1300
@@ -171,6 +171,11 @@
typeset -f schedule=$(add_date_jitter | $SED -e 's/\\//g')
typeset repo=$($SVCPROP -p config/repository $SMF_FMRI)
+ SAVED_IFS="$IFS"
+ IFS=,
+ set -A publishers $($SVCPROP -p config/publishers $SMF_FMRI)
+ IFS="$SAVED_IFS"
+
if [ ! -f $repo/pkg5.repository ]; then
repo_parent=$(dirname $repo)
repo_base=$(basename $repo)
@@ -190,6 +195,7 @@
check_failure $? "unable to create repository" \
$SMF_FMRI degrade
fi
+ set_default_publisher "$repo" ${publishers[0]}
add_cronjob $SMF_FMRI "$schedule" \
"/usr/sbin/svcadm refresh $SMF_FMRI"
}
@@ -205,6 +211,24 @@
}
#
+# Checks whether the given repository has a publisher/prefix set,
+# and if not, sets it to the given publisher.
+#
+# Usage:
+# set_default_publisher <path to repo> <publisher>
+#
+function set_default_publisher {
+ typeset repo="$1"
+ typeset pub=$2
+
+ DEFAULT=$($PKGREPO -s "$repo" get -H publisher/prefix | \
+ $AWK '{print $NF}')
+ if [ "$DEFAULT" = '""' ]; then
+ $PKGREPO -s "$repo" set publisher/prefix=$pub
+ fi
+}
+
+#
# Intended to be called as part of a cron job firing, this calls
# 'pkgrecv_from_origin' for each publisher configured in the SMF
# instance.
@@ -399,6 +423,8 @@
else
# otherwise, we only log messages containing pkg5 FMRIs
$GREP 'pkg:/' $LOG.tmp >> $LOG
+ # we only destroy the cache if a pkgrecv was successful
+ $RM -rf "$cachedir"/$instance
fi
$PKGREPO -s "$repo" refresh
$RM $LOG.tmp