Esempio n. 1
0
    def get_link(self, link_sha, need_data=False):
        """ Get a history link by its sha1 hash. """
        links = self.get(link_sha, None)
        if links is None:
            raise IOError("Unresolved link: " + str_sha(link_sha))

        assert len(links) > 0
        # REDFLAG: Fully think through.
        # The same link can exist in multiple files.
        link = links[0]

        if (not need_data) or (not link[3] is None):
            return link

        index = link[5]
        self.files[index].seek(link[4])
        ret = read_link(self.files[index], True)
        if ret is None:
            raise IOError("Couldn't read blob from disk.")

        assert ret[0] == link[0]
        assert ret[1] == link[1]
        assert ret[2] == link[2]
        assert not ret[3] is None
        assert ret[0] ==  link_sha
        return ret
Esempio n. 2
0
def raw_block_read(link_map, ordinal):
    """ Read a single block file. """
    table = {}
    in_stream = link_map.files[ordinal]
    in_stream.seek(0)
    while True:
        start_pos = in_stream.tell()
        link = read_link(in_stream, False, start_pos, ordinal)
        # read_link() never returns None except for eof, right?
        # Otherwise we'd only do a partial read...
        if link is None:
            break
        entry = table.get(link[0], [])
        entry.append(link)
        table[link[0]] = entry
    return table
Esempio n. 3
0
    def read_from_stream(self, in_stream, index, keep_data=False):
        """ Read links from a stream. """
        age = 0
        count = 0
        while True:
            link = read_link(in_stream, keep_data, in_stream.tell(),
                             index)
            if link is None:
                break

            age = max(age, link[1])
            prev = list(self.get(link[0], []))
            link = list(link) # REDFLAG: ??? tuple -> list -> tuple
            prev.append(tuple(link))
            self[link[0]] = tuple(prev)
            count += 1

        return age, count