Beispiel #1
0
def _copyData(inFile, outFile, totalSize):
    bytesToRead = totalSize
    while totalSize > 0:
        toRead = min(BUFFER_SIZE, totalSize)

        try:
            data = inFile.read(toRead)
        except IOError as e:
            error = "error reading file: %s" % e
            log.error(error)
            raise se.MiscFileReadException(error)

        if not data:
            error = "partial data %s from %s" % \
                    (bytesToRead - totalSize, bytesToRead)
            log.error(error)
            raise se.MiscFileReadException(error)

        outFile.write(data)
        # outFile may not be a real file object but a wrapper.
        # To ensure that we don't use more memory as the input buffer size
        # we flush on every write.
        outFile.flush()

        totalSize = totalSize - len(data)
Beispiel #2
0
 def delay(self):
     # TODO: Raising MiscFileReadException for all errors to keep the old
     # behavior. Should probably use StorageDomainAccessError.
     if self.rc != 0:
         raise exception.MiscFileReadException(self.path, self.rc, self.err)
     if not self.err:
         raise exception.MiscFileReadException(self.path, "no stats")
     stats = self.err.splitlines()[-1]
     match = self._PATTERN.match(stats)
     if not match:
         raise exception.MiscFileReadException(self.path,
                                               "no match: %r" % stats)
     seconds = match.group(1)
     try:
         return float(seconds)
     except ValueError as e:
         raise exception.MiscFileReadException(self.path, e)