[28745] trunk/base/src/pextlib1.0/curl.c

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 8 03:07:03 PDT 2007


Revision: 28745
          http://trac.macosforge.org/projects/macports/changeset/28745
Author:   afb at macports.org
Date:     2007-09-08 03:07:03 -0700 (Sat, 08 Sep 2007)

Log Message:
-----------
add --remote-time support to curl fetch

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/curl.c

Modified: trunk/base/src/pextlib1.0/curl.c
===================================================================
--- trunk/base/src/pextlib1.0/curl.c	2007-09-08 10:05:18 UTC (rev 28744)
+++ trunk/base/src/pextlib1.0/curl.c	2007-09-08 10:07:03 UTC (rev 28745)
@@ -43,6 +43,10 @@
 #include <string.h>
 #endif
 
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#endif
+
 #include <curl/curl.h>
 
 #include <tcl.h>
@@ -124,7 +128,7 @@
 /**
  * curl fetch subcommand entry point.
  *
- * syntax: curl fetch [-v] [--disable-epsv] [--ignore-ssl-cert] [-u userpass] [--effective-url lasturlvar] url filename
+ * syntax: curl fetch [-v] [--disable-epsv] [--ignore-ssl-cert] [--remote-time] [-u userpass] [--effective-url lasturlvar] url filename
  *
  * @param interp		current interpreter
  * @param objc			number of parameters
@@ -142,6 +146,7 @@
 		int noprogress = 1;
 		int useepsv = 1;
 		int ignoresslcert = 0;
+		int remotetime = 0;
 		const char* theUserPassString = NULL;
 		const char* effectiveURLVarName = NULL;
 		char* effectiveURL = NULL;
@@ -149,6 +154,7 @@
 		int lastoption;
 		const char* theURL;
 		const char* theFilePath;
+		long theFileTime = 0;
 		CURLcode theCurlCode;
 		struct curl_slist *headers = NULL;
 		
@@ -167,6 +173,8 @@
 				useepsv = 0;
 			} else if (strcmp(theOption, "--ignore-ssl-cert") == 0) {
 				ignoresslcert = 1;
+			} else if (strcmp(theOption, "--remote-time") == 0) {
+				remotetime = 1;
 			} else if (strcmp(theOption, "-u") == 0) {
 				/* check we also have the parameter */
 				if (optioncrsr < lastoption) {
@@ -296,6 +304,13 @@
 			}
 		}
 
+		/* we want/don't want remote time */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FILETIME, remotetime);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
 		/* set the l/p, if any */
 		if (theUserPassString) {
 			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_USERPWD, theUserPassString);
@@ -324,6 +339,18 @@
 		(void) fclose( theFile );
 		theFile = NULL;
 		
+#ifdef HAVE_UTIME_H
+		if (remotetime) {
+			theCurlCode = curl_easy_getinfo(theHandle, CURLINFO_FILETIME, &theFileTime);
+			if (theFileTime > 0) {
+				struct utimbuf times;
+				times.actime = (time_t)theFileTime;
+				times.modtime = (time_t)theFileTime;
+				utime(theFilePath, &times); /* set the time we got */
+			}
+		}
+#endif /*HAVE_UTIME_H*/
+		
 		/* free header memory */
 		curl_slist_free_all(headers);
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070908/c3bff810/attachment.html


More information about the macports-changes mailing list