Logo Search packages:      
Sourcecode: obnam version File versions  Download package

def obnamlib::repo::Repository::put_chunk (   self,
  data,
  checksum 
)
Put chunk of data into repository.

checksum is the checksum of the data, and must be the same
value as returned by self.checksum(data). However, since all
known use cases require the caller to know the checksum before
calling this method, and since computing checksums is
expensive, we micro-optimize a little bit by passing it as
an argument.

If the same data is already in the repository, it will be put there
a second time. It is the caller's responsibility to check
that the data is not already in the repository.

Return the unique identifier of the new chunk.

Definition at line 520 of file repo.py.

                                       :
        '''Put chunk of data into repository.
        
        checksum is the checksum of the data, and must be the same
        value as returned by self.checksum(data). However, since all
        known use cases require the caller to know the checksum before
        calling this method, and since computing checksums is
        expensive, we micro-optimize a little bit by passing it as
        an argument.
        
        If the same data is already in the repository, it will be put there
        a second time. It is the caller's responsibility to check
        that the data is not already in the repository.
        
        Return the unique identifier of the new chunk.
        
        '''
        
        def random_chunkid():
            return random.randint(0, obnamlib.MAX_ID)
        
        tracing.trace('putting chunk (checksum=%s)', repr(checksum))
        self.require_started_generation()
        if self.prev_chunkid is None:
            self.prev_chunkid = random_chunkid()
        while True:
            chunkid = (self.prev_chunkid + 1) % obnamlib.MAX_ID
            filename = self._chunk_filename(chunkid)
            if not self.fs.exists(filename):
                break
            self.prev_chunkid = random_chunkid() # pragma: no cover
        tracing.trace('chunkid=%s', chunkid)
        self.prev_chunkid = chunkid
        if not self.fs.exists('chunks'):
            self.fs.mkdir('chunks')
            self.hooks.call('repository-toplevel-init', self, 'chunks')
        dirname = os.path.dirname(filename)
        if not self.fs.exists(dirname):
            self.fs.makedirs(dirname)
        self.fs.write_file(filename, data)
        checksum = self.checksum(data)
        self.chunklist.add(chunkid, checksum)
        self.chunksums.add(checksum, chunkid, self.current_client_id)
        return chunkid
        

Generated by  Doxygen 1.6.0   Back to index