Esempio n. 1
0
 def _put(self, hash, fd):
     try:
         req = urllib2.Request(bfutil.urljoin(self.baseurl, hash), fd)
         resp = self.opener.open(req)
         return self._stat(hash) and 1 or 0
     except urllib2.HTTPError, e:
         return 1
Esempio n. 2
0
 def _getfile(self, tmpfile, filename, hash):
     (baseurl, authinfo) = url_.getauthinfo(self.url)
     url = bfutil.urljoin(baseurl, hash)
     try:
         request = urllib2.Request(url)
         infile = self.opener.open(request)
     except urllib2.HTTPError, err:
         detail = _("HTTP error: %s %s") % (err.code, err.msg)
         raise basestore.StoreError(filename, hash, url, detail)
Esempio n. 3
0
 def _getfile(self, tmpfile, filename, hash):
     (baseurl, authinfo) = url_.getauthinfo(self.url)
     url = bfutil.urljoin(baseurl, hash)
     try:
         request = urllib2.Request(url)
         infile = self.opener.open(request)
     except urllib2.HTTPError, err:
         detail = _("HTTP error: %s %s") % (err.code, err.msg)
         raise basestore.StoreError(filename, hash, url, detail)
Esempio n. 4
0
 def __init__(self, ui, repo, remote):
     self.baseurl = bfutil.urljoin(remote.url(), 'bfile')
     try:
         # Mercurial >= 1.9
         self.baseurl, authinfo = util.url(self.baseurl).authinfo()
     except AttributeError:
         # Mercurial <= 1.8
         self.baseurl, authinfo = url_.getauthinfo(self.baseurl)
     self.opener = url_.opener(repo.ui, authinfo)
     super(kilnstore, self).__init__(ui, repo, remote.url())
Esempio n. 5
0
 def _stat(self, hash):
     try:
         req = urllib2.Request(bfutil.urljoin(self.baseurl, hash))
         req.add_header('SHA1-Request', hash)
         return int(hash != \
             self.opener.open(req).info().getheader('Content-SHA1'))
     except urllib2.HTTPError, e:
         if e.code == 404:
             return 2
         else:
             raise
Esempio n. 6
0
 def _verify(self, hash):
     baseurl, authinfo = url_.getauthinfo(self.url)
     store_path = bfutil.urljoin(baseurl, hash)
     request = urllib2.Request(store_path)
     request.add_header('SHA1-Request', hash)
     try:
         url = self.opener.open(request)
         if 'Content-SHA1' in url.info() and hash == url.info()['Content-SHA1']:
             return True
         else:
             return False
     except:
         return False
Esempio n. 7
0
 def _verify(self, hash):
     baseurl, authinfo = url_.getauthinfo(self.url)
     store_path = bfutil.urljoin(baseurl, hash)
     request = urllib2.Request(store_path)
     request.add_header('SHA1-Request', hash)
     try:
         url = self.opener.open(request)
         if 'Content-SHA1' in url.info() and hash == url.info(
         )['Content-SHA1']:
             return True
         else:
             return False
     except:
         return False
Esempio n. 8
0
    def sendfile(self, filename, hash):
        if self._verify(hash):
            return

        self.ui.debug('httpstore.sendfile(%s, %s)\n' % (filename, hash))
        baseurl, authinfo = url_.getauthinfo(self.url)
        fd = None
        try:
            fd = url_.httpsendfile(filename, 'rb')
            request = urllib2.Request(bfutil.urljoin(baseurl, hash), fd)
            try:
                url = self.opener.open(request)
                self.ui.note(_('[OK] %s/%s\n') % (self.rawurl, url.geturl()))
            except urllib2.HTTPError, e:
                raise util.Abort(_('unable to POST: %s\n') % e.msg)
        except Exception, e:
            raise util.Abort(_('%s') % e)
Esempio n. 9
0
    def sendfile(self, filename, hash):
        if self._verify(hash):
            return

        self.ui.debug('httpstore.sendfile(%s, %s)\n' % (filename, hash))
        baseurl, authinfo = url_.getauthinfo(self.url)
        fd = None
        try:
            fd = url_.httpsendfile(filename, 'rb')
            request = urllib2.Request(bfutil.urljoin(baseurl, hash), fd)
            try:
                url = self.opener.open(request)
                self.ui.note(_('[OK] %s/%s\n') % (self.rawurl, url.geturl()))
            except urllib2.HTTPError, e:
                raise util.Abort(_('unable to POST: %s\n') % e.msg)
        except Exception, e:
            raise util.Abort(_('%s') % e)
Esempio n. 10
0
    def _verifyfile(self, cctx, cset, contents, standin, verified):
        baseurl, authinfo = url_.getauthinfo(self.url)
        filename = bfutil.split_standin(standin)
        if not filename:
            return False
        fctx = cctx[standin]
        key = (filename, fctx.filenode())
        if key in verified:
            return False

        expect_hash = fctx.data()[0:40]
        store_path = bfutil.urljoin(baseurl, expect_hash)
        verified.add(key)

        request = urllib2.Request(store_path)
        request.add_header('SHA1-Request', expect_hash)
        try:
            url = self.opener.open(request)
            if 'Content-SHA1' in url.info():
                rhash = url.info()['Content-SHA1']
                if rhash == expect_hash:
                    return False
                else:
                    self.ui.warn(
                        _('changeset %s: %s: contents differ\n (%s)\n') %
                        (cset, filename, store_path))
                    return True  # failed
            else:
                self.ui.warn(
                    _('remote did not send a hash, '
                      'it probably does not understand this protocol\n'))
                return False
        except urllib2.HTTPError, e:
            if e.code == 404:
                self.ui.warn(
                    _('changeset %s: %s missing\n (%s)\n') %
                    (cset, filename, store_path))
                return True  # failed
            else:
                raise util.Abort(
                    _('check failed, unexpected response'
                      'status: %d: %s') % (e.code, e.msg))
Esempio n. 11
0
    def _verifyfile(self, cctx, cset, contents, standin, verified):
        baseurl, authinfo = url_.getauthinfo(self.url)
        filename = bfutil.split_standin(standin)
        if not filename:
            return False
        fctx = cctx[standin]
        key = (filename, fctx.filenode())
        if key in verified:
            return False

        expect_hash = fctx.data()[0:40]
        store_path = bfutil.urljoin(baseurl, expect_hash)
        verified.add(key)

        request = urllib2.Request(store_path)
        request.add_header('SHA1-Request',expect_hash)
        try:
            url = self.opener.open(request)
            if 'Content-SHA1' in url.info():
                rhash = url.info()['Content-SHA1']
                if rhash == expect_hash:
                    return False
                else:
                    self.ui.warn(
                        _('changeset %s: %s: contents differ\n (%s)\n')
                        % (cset, filename, store_path))
                    return True             # failed
            else:
                self.ui.warn(_('remote did not send a hash, '
                    'it probably does not understand this protocol\n'))
                return False
        except urllib2.HTTPError, e:
            if e.code == 404:
                self.ui.warn(
                    _('changeset %s: %s missing\n (%s)\n')
                    % (cset, filename, store_path))
                return True                 # failed
            else:
                raise util.Abort(_('check failed, unexpected response'
                                   'status: %d: %s') % (e.code, e.msg))
Esempio n. 12
0
 def __init__(self, ui, repo, url):
     url = bfutil.urljoin(url, 'bfile')
     super(httpstore, self).__init__(ui, repo, url)
     self.rawurl, self.path = urlparse.urlsplit(self.url)[1:3]
     (baseurl, authinfo) = url_.getauthinfo(self.url)
     self.opener = url_.opener(self.ui, authinfo)
Esempio n. 13
0
 def __init__(self, ui, repo, url):
     url = bfutil.urljoin(url, 'bfile')
     super(httpstore, self).__init__(ui, repo, url)
     self.rawurl, self.path = urlparse.urlsplit(self.url)[1:3]
     (baseurl, authinfo) = url_.getauthinfo(self.url)
     self.opener = url_.opener(self.ui, authinfo)
Esempio n. 14
0
 def _get(self, hash):
     req = urllib2.Request(bfutil.urljoin(self.baseurl, hash))
     return (None, self.opener.open(req))