From 48c0f8b99203e1ade6fb9ffb5a5ed37bdb4f5369 Mon Sep 17 00:00:00 2001 From: cperciva Date: Tue, 7 Aug 2007 19:33:46 +0000 Subject: When storing old versions of files for use in generating new files via patching and for rolling back updates, don't copy a file if it has already been stored. This provides a significant speedup to the "Preparing to download files" stage of "freebsd-update fetch" if many updates have already been applied or if a file being updated is linked many times (such as /rescue/*). Reported by: Paul Dekkers MFC after: 1 week Approved by: re (bmah) --- usr.sbin/freebsd-update/freebsd-update.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'usr.sbin/freebsd-update') diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh index 552057e..a08517c 100644 --- a/usr.sbin/freebsd-update/freebsd-update.sh +++ b/usr.sbin/freebsd-update/freebsd-update.sh @@ -1365,12 +1365,27 @@ fetch_files_prepare () { # Copy all files into /files/. We only need the unmodified files # for use in patching; but we'll want all of them if the user asks # to rollback the updates later. - cut -f 1 -d '|' < $2.hashes | - while read F; do + while read LINE; do + F=`echo "${LINE}" | cut -f 1 -d '|'` + HASH=`echo "${LINE}" | cut -f 2 -d '|'` + + # Skip files we already have. + if [ -f files/${HASH}.gz ]; then + continue + fi + + # Make sure the file hasn't changed. cp "${BASEDIR}/${F}" tmpfile - gzip -c < tmpfile > files/`sha256 -q tmpfile`.gz + if [ `sha256 -q tmpfile` != ${HASH} ]; then + echo + echo "File changed while FreeBSD Update running: ${F}" + return 1 + fi + + # Place the file into storage. + gzip -c < tmpfile > files/${HASH}.gz rm tmpfile - done + done < $2.hashes # Produce a list of patches to download sort -k 1,1 -t '|' $3.hashes | @@ -1665,7 +1680,7 @@ fetch_run () { # Prepare to fetch files: Generate a list of the files we need, # copy the unmodified files we have into /files/, and generate # a list of patches to download. - fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW + fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 # Fetch files. fetch_files || return 1 -- cgit v1.1