SF.net SVN: gar:[23486] csw/mgar/gar/v2/lib/python/rest.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Wed Apr 23 10:11:15 CEST 2014


Revision: 23486
          http://sourceforge.net/p/gar/code/23486
Author:   wahwah
Date:     2014-04-23 08:11:13 +0000 (Wed, 23 Apr 2014)
Log Message:
-----------
csw-upload-pkg: Handle HTTP 409

Add an error messages with an explanation of what's going on: you can't upload
the same filename with a different content.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2014-04-22 23:10:27 UTC (rev 23485)
+++ csw/mgar/gar/v2/lib/python/rest.py	2014-04-23 08:11:13 UTC (rev 23486)
@@ -440,8 +440,8 @@
         c.getinfo(pycurl.EFFECTIVE_URL))
     c.close()
     logging.debug("HTTP code: %s", http_code)
-    if http_code == 401:
-      raise RestCommunicationError("Received HTTP code {0}".format(http_code))
+    if http_code == 401 or (http_code >= 500 and http_code < 600):
+      raise RestCommunicationError("Received HTTP code {0}: {0}".format(http_code, d.getvalue()))
     successful = (http_code >= 200 and http_code <= 299)
     metadata = None
     if successful:
@@ -459,11 +459,12 @@
     c.setopt(pycurl.URL, url)
     c.setopt(pycurl.POST, 1)
     c = self._SetAuth(c)
+    basename = os.path.basename(filename)
     post_data = [
         ('srv4_file', (pycurl.FORM_FILE, filename)),
         ('submit', 'Upload'),
         ('md5_sum', md5_sum),
-        ('basename', os.path.basename(filename)),
+        ('basename', basename),
     ]
     c.setopt(pycurl.HTTPPOST, post_data)
     c.setopt(pycurl.WRITEFUNCTION, d.write)
@@ -480,8 +481,17 @@
       logging.debug("*** Data")
       logging.debug(d.getvalue())
     logging.debug("File POST http code: %s", http_code)
-    if http_code >= 400 and http_code <= 499:
-      raise RestCommunicationError("%s - HTTP code: %s" % (url, http_code))
+    if http_code == 409:
+      msg = ('The server returned HTTP 409 conflict. This probably means '
+             'that there already is a file named {0} in the allpkgs '
+             'directory. You must not overwrite the same file name '
+             'with new content. If you really need to upload a new version '
+             'of your package, add a new REV stamp to it, so that the file '
+             'name becomes unique..'.format(basename))
+      raise RestCommunicationError(msg)
+    if http_code >= 400 and http_code < 600:
+      msg = "{0} - HTTP code: {1}: {2}".format(url, http_code, d.getvalue())
+      raise RestCommunicationError(msg)
 
 
 class CachedPkgstats(object):

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list