[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fetch improvement



Checking the size is okay doesn't need many lines of code, and it's
very cheap computationally.

Any objections ?

Index: bsd.port.mk
===================================================================
RCS file: /cvs/ports/infrastructure/mk/bsd.port.mk,v
retrieving revision 1.672
diff -u -p -u -r1.672 bsd.port.mk
--- bsd.port.mk	21 Dec 2004 20:56:54 -0000	1.672
+++ bsd.port.mk	4 Jan 2005 15:33:26 -0000
@@ -1197,6 +1197,8 @@ _DO_LOCK=\
 .else
 _DO_LOCK=:
 .endif
+
+_size_fragment=wc -c $$file | awk -v OFS=  '{print "SIZE (",$$2,") = ",$$1}' 
 ###
 ### end of variable setup. Only targets now
 ###
@@ -1259,6 +1261,10 @@ makesum: fetch-all
 		for cipher in ${_CIPHERS}; do \
 			$$cipher ${_CKSUMFILES} >> ${CHECKSUM_FILE}; \
 	    done
+	@cd ${DISTDIR} && \
+		for file in ${_CKSUMFILES}; do \
+			${_size_fragment} >> ${CHECKSUM_FILE}; \
+		done
 	@sort -u -o ${CHECKSUM_FILE} ${CHECKSUM_FILE}
 .endif
 
@@ -1270,6 +1276,10 @@ addsum: fetch-all
 	 	for cipher in ${_CIPHERS}; do \
 			$$cipher ${_CKSUMFILES} >> ${CHECKSUM_FILE}; \
 	    done
+	@cd ${DISTDIR} && \
+		for file in ${_CKSUMFILES}; do \
+			${_size_fragment} >> ${CHECKSUM_FILE}; \
+		done
 	@sort -u -o ${CHECKSUM_FILE} ${CHECKSUM_FILE}
 	@if [ `sed -e 's/\=.*$$//' ${CHECKSUM_FILE} | uniq -d | wc -l` -ne 0 ]; then \
 		echo "Inconsistent checksum in ${CHECKSUM_FILE}"; \
@@ -1949,7 +1959,19 @@ ${_F}:
 	for site in $$sites; do \
 		${ECHO_MSG} ">> Attempting to fetch ${_F} from $${site}."; \
 		if ${FETCH_CMD} $${site}$$f; then \
-				exit 0; \
+				file=${_F:S_(_at_)_^${DISTDIR}/@@}; \
+				ck=`${_size_fragment}`; \
+				if grep -q "^$$ck\$$" ${CHECKSUM_FILE}; then \
+					${ECHO_MSG} ">> Size matches for ${_F}"; \
+					exit 0; \
+				else \
+					if grep -q "SIZE ($$file)" ${CHECKSUM_FILE}; then \
+						${ECHO_MSG} ">> Size does not match for ${_F}"; \
+					else \
+						${ECHO_MSG} ">> No size recorded for ${_F}"; \
+						exit 0; \
+					fi; \
+				fi; \
 		fi; \
 	done; exit 1
 .  endif



Visit your host, monkey.org