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.

:
'''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 isNone:
self.prev_chunkid = random_chunkid()
whileTrue:
chunkid = (self.prev_chunkid + 1) % obnamlib.MAX_ID
filename = self._chunk_filename(chunkid)
ifnot self.fs.exists(filename):
break
self.prev_chunkid = random_chunkid() # pragma: no cover
tracing.trace('chunkid=%s', chunkid)
self.prev_chunkid = chunkid
ifnot self.fs.exists('chunks'):
self.fs.mkdir('chunks')
self.hooks.call('repository-toplevel-init', self, 'chunks')
dirname = os.path.dirname(filename)
ifnot 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