Esempio n. 1
0
 def xmlrpc_uploadFile(self, recipe_test_id, name, size, digest, offset,
                       data):
     log.debug("XMLRPC: results.uploadFile(%r, %r, %r, %r, %r, %r)",
               recipe_test_id, name, size, digest, offset, data)
     file_id = self.get_file(name,
                             size=size,
                             digest=(digests.which_digest(digest), None))
     if file_id is None:
         msg = "%s:xmlrpc_uploadFile: " % self.__class__.__name__ + \
                 "Can not create file '%s'." % name
         self.main.error(msg)
         return msg
     if offset < 0:
         if digest:
             digest = digests.mk_digest(digest)
             if digest:
                 evt = event.file_meta(file_id, digest=digest)
                 self.main.send_evt(evt)
         evt = event.file_close(file_id)
         self.main.send_evt(evt)
         return 0
     if data:
         # FIXME: is chunk's digest necessary?
         evt = event.file_write(file_id, data, offset=offset, digest=digest)
         self.main.send_evt(evt)
     return 0  # or "Failure reason"
Esempio n. 2
0
 def xmlrpc_uploadFile(self, recipe_test_id, name, size, digest, offset,
         data):
     log.debug("XMLRPC: results.uploadFile(%r, %r, %r, %r, %r, %r)",
             recipe_test_id, name, size, digest, offset, data)
     file_id = self.get_file(name, size=size,
             digest=(digests.which_digest(digest), None))
     if file_id is None:
         msg = "%s:xmlrpc_uploadFile: " % self.__class__.__name__ + \
                 "Can not create file '%s'." % name
         self.main.error(msg)
         return msg
     if offset < 0:
         if digest:
             digest = digests.mk_digest(digest)
             if digest:
                 evt = event.file_meta(file_id, digest=digest)
                 self.main.send_evt(evt)
         evt = event.file_close(file_id)
         self.main.send_evt(evt)
         return 0
     if data:
         # FIXME: is chunk's digest necessary?
         evt = event.file_write(file_id, data, offset=offset, digest=digest)
         self.main.send_evt(evt)
     return 0 # or "Failure reason"
Esempio n. 3
0
 def uploadFile(self, path, name, size, md5sum, offset, data):
     #path: the relative path to upload to
     #name: the name of the file
     #size: size of contents (bytes)
     #md5: md5sum (hex digest) of contents
     #data: base64 encoded file contents
     #offset: the offset of the chunk
     # files can be uploaded in chunks, if so the md5 and size describe
     # the chunk rather than the whole file. the offset indicates where
     # the chunk belongs
     # the special offset -1 is used to indicate the final chunk
     contents = base64.decodestring(data)
     del data
     # we will accept offset and size as strings to work around xmlrpc limits
     offset = decode_int(offset)
     size = decode_int(size)
     digest_method = digests.which_digest(md5sum)
     if digest_method:
         digest_constructor = digests.DigestConstructor(digest_method)
     else:
         digest_constructor = None
     if offset != -1:
         if size is not None:
             if size != len(contents): return False
         if digest_constructor:
             if md5sum != digest_constructor(contents).hexdigest():
                 return False
     uploadpath = self.basepath
     #XXX - have an incoming dir and move after upload complete
     # SECURITY - ensure path remains under uploadpath
     path = os.path.normpath(path)
     if path.startswith('..'):
         raise BX(_("Upload path not allowed: %s" % path))
     udir = "%s/%s" % (uploadpath, path)
     ensuredir(udir)
     fn = "%s/%s" % (udir, name)
     try:
         st = os.lstat(fn)
     except OSError, e:
         if e.errno == errno.ENOENT:
             pass
         else:
             raise
Esempio n. 4
0
 def uploadFile(self, path, name, size, md5sum, offset, data):
     #path: the relative path to upload to
     #name: the name of the file
     #size: size of contents (bytes)
     #md5: md5sum (hex digest) of contents
     #data: base64 encoded file contents
     #offset: the offset of the chunk
     # files can be uploaded in chunks, if so the md5 and size describe
     # the chunk rather than the whole file. the offset indicates where
     # the chunk belongs
     # the special offset -1 is used to indicate the final chunk
     contents = base64.decodestring(data)
     del data
     # we will accept offset and size as strings to work around xmlrpc limits
     offset = decode_int(offset)
     size = decode_int(size)
     digest_method = digests.which_digest(md5sum)
     if digest_method:
         digest_constructor = digests.DigestConstructor(digest_method)
     else:
         digest_constructor = None
     if offset != -1:
         if size is not None:
             if size != len(contents): return False
         if digest_constructor:
             if md5sum != digest_constructor(contents).hexdigest():
                 return False
     uploadpath = self.basepath
     #XXX - have an incoming dir and move after upload complete
     # SECURITY - ensure path remains under uploadpath
     path = os.path.normpath(path)
     if path.startswith('..'):
         raise BX(_("Upload path not allowed: %s" % path))
     udir = "%s/%s" % (uploadpath,path)
     ensuredir(udir)
     fn = "%s/%s" % (udir,name)
     try:
         st = os.lstat(fn)
     except OSError, e:
         if e.errno == errno.ENOENT:
             pass
         else:
             raise