| |
@@ -22,7 +22,7 @@
|
| |
|
| |
import pycurl
|
| |
import six
|
| |
- from six.moves import http_client
|
| |
+ from six.moves import http_client, urllib
|
| |
|
| |
from .errors import (AlreadyUploadedError, DownloadError, InvalidHashType,
|
| |
UploadError)
|
| |
@@ -157,7 +157,7 @@
|
| |
return
|
| |
|
| |
self.log.info("Downloading %s", filename)
|
| |
- urled_file = filename.replace(' ', '%20')
|
| |
+ urled_file = urllib.parse.quote(filename)
|
| |
url = self.get_download_url(name, urled_file, hash, hashtype, **kwargs)
|
| |
if isinstance(url, six.text_type):
|
| |
url = url.encode('utf-8')
|
| |
@@ -200,6 +200,38 @@
|
| |
if not self.file_is_valid(outfile, hash, hashtype=hashtype):
|
| |
raise DownloadError('%s failed checksum' % filename)
|
| |
|
| |
+ def remote_file_exists_head(self, name, filename, hash):
|
| |
+ """Verify whether a file exists on the lookaside cache.
|
| |
+ Uses a HTTP HEAD request and doesn't require authentication.
|
| |
+
|
| |
+ :param str name: The name of the module. (usually the name of the
|
| |
+ SRPM). This can include the namespace as well (depending on what
|
| |
+ the server side expects).
|
| |
+ :param str filename: The name of the file to check for.
|
| |
+ :param str hash: The known good hash of the file.
|
| |
+ """
|
| |
+
|
| |
+ urled_file = urllib.parse.quote(filename)
|
| |
+ url = self.get_download_url(name, urled_file, hash, self.hashtype)
|
| |
+
|
| |
+ c = pycurl.Curl()
|
| |
+ c.setopt(pycurl.URL, url)
|
| |
+ c.setopt(pycurl.NOBODY, True)
|
| |
+ c.setopt(pycurl.FOLLOWLOCATION, 1)
|
| |
+
|
| |
+ try:
|
| |
+ c.perform()
|
| |
+ status = c.getinfo(pycurl.RESPONSE_CODE)
|
| |
+ except Exception as e:
|
| |
+ raise DownloadError(e)
|
| |
+ finally:
|
| |
+ c.close()
|
| |
+
|
| |
+ if status != 200:
|
| |
+ self.log.debug('Unavailable file \'%s\' at %s' % (filename, url))
|
| |
+ return False
|
| |
+ return True
|
| |
+
|
| |
def remote_file_exists(self, name, filename, hash):
|
| |
"""Verify whether a file exists on the lookaside cache
|
| |
|
| |
A query about whether some file is present in the lookaside cache was
under authentication and it prevented using command
pre-push-check
for those without the 'packager' permission.
Added another method (based on HTTP HEAD), that allows the same check
without authentication.
JIRA: RHELCMP-11485
Fixes: https://pagure.io/fedpkg/issue/513
Signed-off-by: Ondrej Nosek onosek@redhat.com