pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk 2nd round for PKG_RESUME_TRANSFERS:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/e8762cb24b06
branches:  trunk
changeset: 482379:e8762cb24b06
user:      xtraeme <xtraeme%pkgsrc.org@localhost>
date:      Tue Oct 26 21:14:59 2004 +0000

description:
2nd round for PKG_RESUME_TRANSFERS:

* Add FETCH_OUTPUT_ARGS (new option, defaults to "-o" with NetBSD's ftp(1))
* Use FETCH_OUTPUT_ARGS to move the file transfer to a temporary name
 on ${DISTDIR}/${DIST_SUBDIR} with extension ".temp"
* If temporary file matches the checksum recorded in distinfo, move it
 to the original name (removing temp file)

For example, if you want to use PKG_RESUME_TRANSFERS with wget
(pkgsrc/net/wget), the following vars should be defined in mk.conf:

FETCH_CMD=wget
FETCH_RESUME_ARGS=-c
FETCH_OUTPUT_ARGS=-O

No need to set these vars when using defaults (NetBSD's ftp(1))

diffstat:

 mk/bsd.pkg.mk       |  64 ++++++++++++++++++++++++++++++++++++++++++----------
 mk/defaults/mk.conf |  12 +++++++++-
 2 files changed, 62 insertions(+), 14 deletions(-)

diffs (123 lines):

diff -r 5f8641f22896 -r e8762cb24b06 mk/bsd.pkg.mk
--- a/mk/bsd.pkg.mk     Tue Oct 26 21:13:51 2004 +0000
+++ b/mk/bsd.pkg.mk     Tue Oct 26 21:14:59 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: bsd.pkg.mk,v 1.1524 2004/10/26 02:23:37 lukem Exp $
+#      $NetBSD: bsd.pkg.mk,v 1.1525 2004/10/26 21:14:59 xtraeme Exp $
 #
 # This file is in the public domain.
 #
@@ -1462,37 +1462,75 @@
 # adding pre-* or post-* targets/scripts, override these.
 ################################################################
 
-# Resume a previous transfer not finished totally.
+###
+### _RESUME_TRANSFER:
+###
+### Macro to resume a previous transfer, needs to have defined
+### the following options in mk.conf:
+###
+### PKG_RESUME_TRANSFERS
+### FETCH_RESUME_ARGS (if FETCH_CMD != default)
+### FETCH_OUTPUT_ARGS (if FETCH_CMD != default)
+###
+### For example if you want to use wget (pkgsrc/net/wget):
+###
+### FETCH_CMD=wget
+### FETCH_RESUME_ARGS=-c
+### FETCH_OUTPUT_ARGS=-O
+###
+### How does it work?
+###
+### FETCH_CMD downloads the file and saves it temporally into $$bfile.temp
+### if the checksum match the correct one, $$bfile.temp is renamed to
+### the original name.
+###
+
 _RESUME_TRANSFER=                                                      \
-       dsize=`${WC} -c < ${DISTDIR}/${DIST_SUBDIR}/$$bfile`;           \
        tsize=`${AWK} '/^Size/ && $$2 == '"\"($$file)\""' { print $$4 }' ${DISTINFO_FILE}` || ${TRUE}; \
+       if [ ! -f "${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp" ]; then      \
+               ${CP} ${DISTDIR}/${DIST_SUBDIR}/$$bfile ${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp; \
+       fi;     \
+       dsize=`${WC} -c < ${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp`;      \
+       if [ "$$dsize" -eq "$$tsize" -a -f "${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp" ]; then     \
+               ${MV} ${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp ${DISTDIR}/${DIST_SUBDIR}/$$bfile; \
+       fi;     \
        case "$$tsize" in                                               \
        "")     ${ECHO_MSG} "No size in distinfo file (${DISTINFO_FILE})"; \
                break ;;                                                \
        esac;                                                           \
-       if ${TEST} -n "$$ftp_proxy" -o -n "$$http_proxy"; then          \
+       if [ -n "$$ftp_proxy" -o -n "$$http_proxy" ]; then              \
                ${ECHO_MSG} "===> Resume is not supported by ftp(1) using http/ftp proxies.";   \
                break;                                                  \
        else                                                            \
-               if ${TEST} "$$dsize" -lt "$$tsize"; then                \
-                       if ${TEST} "${FETCH_CMD:T}" != "ftp" -a         \
-                               -z "${FETCH_RESUME_ARGS}"; then         \
+               if [ "$$dsize" -lt "$$tsize" ]; then            \
+                       if [ "${FETCH_CMD:T}" != "ftp" -a -z "${FETCH_RESUME_ARGS}" ]; then \
                                ${ECHO_MSG} "=> Resume transfers are not supported, FETCH_RESUME_ARGS is empty."; \
                                break;                                  \
                        else                                            \
                                for res_site in $$sites; do                     \
-                                       ${ECHO_MSG} "===> $$bfile not completed, resuming...";  \
-                                       cd ${_DISTDIR};                         \
-                                       ${FETCH_CMD} ${FETCH_BEFORE_ARGS} ${FETCH_RESUME_ARGS} $${res_site}$${bfile}; \
-                                       if ${TEST} $$? -eq 0; then      \
+                                       if [ -z "${FETCH_OUTPUT_ARGS}" ]; then  \
+                                               ${ECHO_MSG} "=> FETCH_OUTPUT_ARGS has to be defined.";  \
+                                               break;                  \
+                                       fi;                             \
+                                       ${ECHO_MSG} "=> $$bfile not completed, resuming:";      \
+                                       ${ECHO_MSG} "=> Downloaded: $$dsize Total: $$tsize.";   \
+                                       ${ECHO_MSG};                    \
+                                       cd ${_DISTDIR};                 \
+                                       ${FETCH_CMD} ${FETCH_BEFORE_ARGS} ${FETCH_RESUME_ARGS}  \
+                                               ${FETCH_OUTPUT_ARGS} $${bfile}.temp $${res_site}$${bfile}; \
+                                       if [ $$? -eq 0 ]; then          \
+                                               ndsize=`${WC} -c < ${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp`;     \
+                                               if [ "$$tsize" -eq "$$ndsize" ]; then   \
+                                                       ${MV} ${DISTDIR}/${DIST_SUBDIR}/$$bfile.temp ${DISTDIR}/${DIST_SUBDIR}/$$bfile;                                         \
+                                               fi;                     \
                                                break;                  \
                                        fi;                             \
                                done;                                   \
                        fi;                                             \
-               elif ${TEST} "$$dsize" -gt "$$tsize"; then              \
+               elif [ "$$dsize" -gt "$$tsize" ]; then                  \
                        ${ECHO_MSG} "==> Downloaded file larger than the recorded size.";       \
                        break;                                          \
-               fi;                                                     \
+               fi;                                                     \
        fi
 
 #
diff -r 5f8641f22896 -r e8762cb24b06 mk/defaults/mk.conf
--- a/mk/defaults/mk.conf       Tue Oct 26 21:13:51 2004 +0000
+++ b/mk/defaults/mk.conf       Tue Oct 26 21:14:59 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mk.conf,v 1.9 2004/10/21 17:00:10 tv Exp $
+# $NetBSD: mk.conf,v 1.10 2004/10/26 21:14:59 xtraeme Exp $
 #
 
 # A file providing defaults for pkgsrc and the packages collection.
@@ -257,6 +257,16 @@
 # Default: -R
 # Possible: depends on your FETCH_CMD value.
 
+.if ${FETCH_CMD:T} == "ftp"
+FETCH_OUTPUT_ARGS?=    -o
+.else
+FETCH_OUTPUT_ARGS?=    # empty
+.endif
+# Used when PKG_RESUME_TRANSFERS is enabled, to specify default argument
+# in FETCH_CMD to fetch the file to a temporary name.
+# Default: -o
+# Possible: depends on your FETCH_CMD value.
+
 LIBTOOLIZE_PLIST?=     yes
 # This determines whether to expand libtool archives in PLISTs into the
 # represented library names.



Home | Main Index | Thread Index | Old Index