Example #1
0
    def process(self):
        ck = self.deq()
        try:
            fd = os.open(ck.filename, os.O_RDONLY)
        except OSError as e:
            self.logger.warn("%s, Skipping ... " % e, extra=self.d)
            return

        os.lseek(fd, ck.offset, os.SEEK_SET)
        digest = hashlib.sha1()
        blocksize = 4*1024*1024 # 4MiB block
        blockcount = ck.length / blocksize
        remaining = ck.length % blocksize
        for _ in xrange(blockcount):
            digest.update(readn(fd, blocksize))
        if remaining > 0:
            digest.update(readn(fd, remaining))
        try:
            os.close(fd)
        except Exception as e:
            self.logger.warn(e, extra=self.d)
        ck.digest = digest.hexdigest()
        #self.chunkq.append(ck)
        self.vsize += ck.length

        self.bfsign.insert_item(ck.digest)
Example #2
0
    def process(self):
        ck = self.deq()
        try:
            fd = os.open(ck.filename, os.O_RDONLY)
        except OSError as e:
            self.logger.warn("%s, Skipping ... " % e, extra=self.d)
            return

        os.lseek(fd, ck.offset, os.SEEK_SET)
        digest = hashlib.sha1()
        blocksize = 4 * 1024 * 1024  # 4MiB block
        blockcount = ck.length / blocksize
        remaining = ck.length % blocksize
        for _ in xrange(blockcount):
            digest.update(readn(fd, blocksize))
        if remaining > 0:
            digest.update(readn(fd, remaining))
        try:
            os.close(fd)
        except Exception as e:
            self.logger.warn(e, extra=self.d)
        ck.digest = digest.hexdigest()
        #self.chunkq.append(ck)
        self.vsize += ck.length

        self.bfsign.insert_item(ck.digest)
Example #3
0
    def read_then_write(self, rfd, wfd, work, num_of_bytes, m):
        """ core entry point for copy action: first read then write.

        @param num_of_bytes: the exact amount of bytes we will copy
        @return: False if unsuccessful.

        """
        buf = None
        try:
            buf = readn(rfd, num_of_bytes)
        except IOError:
            self.logger.error("Failed to read %s", work.src, extra=self.d)
            return False

        try:
            writen(wfd, buf)
        except IOError:
            self.logger.error("Failed to write %s", work.dest, extra=self.d)
            return False

        if m:
            m.update(buf)

        return True
Example #4
0
    def read_then_write(self, rfd, wfd, work, num_of_bytes, m):
        """ core entry point for copy action: first read then write.

        @param num_of_bytes: the exact amount of bytes we will copy
        @return: False if unsuccessful.

        """
        buf = None
        try:
            buf = readn(rfd, num_of_bytes)
        except IOError:
            self.logger.error("Failed to read %s", work.src, extra=self.d)
            return False

        try:
            writen(wfd, buf)
        except IOError:
            self.logger.error("Failed to write %s", work.dest, extra=self.d)
            return False

        if m:
            m.update(buf)

        return True