Logo Search packages:      
Sourcecode: jigdo version File versions

bool MkTemplate::run ( const string &  imageLeafName = "image",
const string &  templLeafName = "template" 

First scan through all the individual files, creating checksums, then read image file and find matches. Write .template and .jigdo files.

imageLeafName Name for the image, which should be a relative path name. This does not need to be similar to the filename that the image has now - it is *only* used when creating the .jigdo file, nowhere else. It is the name that will be used when someone reassembles the image.
templLeafName Name to write to jigdo file as template URL. Can be a full http/ftp URL, or a relative URL.
returns FAILURE if any open/read/write/close failed, unless it was that of a file with reportErrors==false.

Definition at line 924 of file mktemplate.cc.

References JigdoCache::begin(), JigdoCache::deallocBuffer(), JigdoCache::end(), MD5Sum::finish(), ArrayAutoPtr< X >::get(), JigdoCache::getBlockLen(), JigdoCache::getMD5BlockLen(), and MD5Sum::update().

  bool result = SUCCESS;
  oldAreaEnd = 0;

  // Kick out files that are too small
  for (JigdoCache::iterator f = cache->begin(), e = cache->end();
       f != e; ++f) {
    if (f->size() < cache->getBlockLen()) {
    fileSizeTotal += f->size();

  // Hash table performance drops when linked lists become long => "+1"
  int    blockBits = bitWidth(fileCount) + 1;
  uint32 blockMask = (1 << blockBits) - 1;
  block.resize(blockMask + 1);

  size_t max_MD5Len_blockLen =
      cache->getBlockLen() + 64; // +64 for Assert below
  if (max_MD5Len_blockLen < cache->getMD5BlockLen())
    max_MD5Len_blockLen = cache->getMD5BlockLen();
  /* Pass 1 imposes no minimum buffer length, only pass 2: Must always
     be able to read readAmount bytes into one buffer half in one go;
     must be able to start calculating an MD5Sum at a position that is
     blockLength bytes back in input; must be able to write out at
     least previous md5BlockLength bytes in case there is no match. */
  size_t bufferLength = 2 *
    (max_MD5Len_blockLen > readAmount ? max_MD5Len_blockLen : readAmount);
  // Avoid reading less bytes than readAmount at any time
  bufferLength = (bufferLength + readAmount - 1) / readAmount * readAmount;

  Paranoid(bufferLength % readAmount == 0); // for efficiency only
  // Asserting this makes things easier in pass 2. Yes it is ">" not ">="
  Assert(cache->getMD5BlockLen() > cache->getBlockLen());

  if (debug) {
    debug("Nr of files: %1 (%2 bits)", fileCount, blockBits);
    debug("Total bytes: %1", fileSizeTotal);
    debug("blockLength: %1", cache->getBlockLen());
    debug("md5BlockLen: %1", cache->getMD5BlockLen());
    debug("bufLen (kB): %1", bufferLength/1024);
    debug("zipQual:     %1", zipQual);

  MD5Sum templMd5Sum;
  ArrayAutoPtr<byte> bufDel(new byte[bufferLength]);
  byte* buf = bufDel.get();

  prepareJigdo(); // Add [Jigdo]

  { // Write header to template file
    string s = TEMPLATE_HDR; append(s, FILEFORMAT_MAJOR); s += '.';
    append(s, FILEFORMAT_MINOR); s += " jigdo-file/" JIGDO_VERSION;
    s += "\r\nSee "; s += URL; s += " for details about jigdo.\r\n\r\n";
    const byte* t = reinterpret_cast<const byte*>(s.data());
    writeBytes(*templ, t, s.size());
    templMd5Sum.update(t, s.size());
    if (!*templ) result = FAILURE;

  // Read input image and output parts that do not match
  if (scanImage(buf, bufferLength, cache->getBlockLen(), blockMask,
                cache->getMD5BlockLen(), templMd5Sum)) {
    result = FAILURE;

  // Add [Image], (re-)add [Parts]
  finalizeJigdo(imageLeafName, templLeafName, templMd5Sum);

  debug("MkTemplate::run() finished");
  return result;

Generated by  Doxygen 1.6.0   Back to index