Esempio n. 1
0
/* Fetch and unpack the archive 'arcHash' into the directory
   'path'. If path="", then just index the archive.
 */
void DirInstaller::unpackBlind(const Hash &arcHash, const std::string &path)
{
  TreePtr job = owner.unpackBlindTarget(path);
  job->addInput(arcHash);
  job->finder = finder;
  if(path != "")
    log("  Blind unpacking " + arcHash.toString() + " => " + path);
  else
    log("  Blind indexing " + arcHash.toString());
  execJob(job);
}
Esempio n. 2
0
void DirInstaller::loadHint(const Hash &hint)
{
  log("Loading HINT=" + hint.toString());

  // Check if there is an archive associated with the given hash
  const ArcRuleData *arc = ptr->origRules->findArchive(hint);

  // If there is no archive rule, then ignore this hint.
  if(!arc)
    {
      log("  No hint archive found, skipping.");
      return;
    }

  log("  Found archive rule: dir=" + arc->dirHash.toString() +
      " arc=" + arc->arcHash.toString());
  DirMap tmp;
  DirPtr arcDir;
  try { arcDir = addDirFile(tmp, arc->dirHash, ""); }
  catch(...)
    {
      // Blind-index archive, then try again
      unpackBlind(arc->arcHash, "");
      // This time, allow the exception to fall through on failure
      arcDir = addDirFile(tmp, arc->dirHash, "");
    }

  // Add archive to the ArcRuleSet.
  ptr->arcRules->addArchive(arc->arcHash, arc->dirHash, arcDir,
                            arc->ruleString);
}
void TrustTreeModel::contentReceived(const Hash& aHashOfContent,
                                     const ProtocolItemType aTypeOfReceivdContent) {
    if ( aTypeOfReceivdContent == UserProfile ) {
        QLOG_STR("TrustTreeModel::contentReceived(), profile=" + aHashOfContent.toString() ) ;
        iController.model().lock() ;
        TrustTreeItem operatorFromTrustList ( (*iTrustTree)[aHashOfContent] ) ;
        if ( operatorFromTrustList.iTrustingOperator != KNullHash ) {
            // ok, operator was in trust list.
            operatorFromTrustList.iNeedsUpdate = true ;
            recalculateTrust()  ;
        }
        iController.model().unlock() ;
    }
}
Esempio n. 4
0
/* Check the rule system if there are any hints associated with a
   given dirHash, then load them.
 */
void DirInstaller::loadDirHints(const Hash &dirHash)
{
  const std::vector<Hash> *hints = ptr->arcRules->findHints(dirHash);
  if(!hints || hints->size() == 0)
    return;

  log("Found rule hints for dirHash=" + dirHash.toString());

  for(int i=0; i<hints->size(); i++)
    {
      const Hash &hint = (*hints)[i];
      loadHint(hint);
    }
}
Esempio n. 5
0
/* Load the directory object 'dirHash' and store results in
   'out'. Fetches the dirfile if necessary, and takes care of dir
   cache bookkeeping. Returns a DirPtr to the loaded dir.

   The 'path' parameter only affects the filenames added to the 'out'
   list. It does not affect the returned DirPtr.
 */
DirPtr DirInstaller::addDirFile(DirMap &out, const Hash &dirHash,
                                const std::string &path)
{
  // Load any hints associated with the dir first
  loadDirHints(dirHash);

  // Fetch the dir file if possible
  std::string dirFile = fetchFile(dirHash);

  // Load and use it
  DirPtr dir(new DirMap);
  owner.loadDir(dirFile, *dir, dirHash);
  Dir::add(out, *dir, path);
  log("Loaded DIR dirHash=" + dirHash.toString());
  return dir;
}
Esempio n. 6
0
void DirInstaller::handleHash(DirMap &out, const Hash &dirHash,
                              HashDir &blinds, const std::string &path)
{
  // Check if there is an archive associated with the given hash
  const ArcRuleData *arc = ptr->origRules->findArchive(dirHash);

  if(!arc)
    {
      log("Hash " + dirHash.toString() + " does NOT match any archive rule, assuming dirHash");

      /* Just load the dir and add it to 'out', along with any hints
         associated with it. We assume this is enough to find all the
         files we need. Throws on error.
       */
      addDirFile(out, dirHash, path);
      return;
    }

  /* We found an archive. Try loading the dirfile and injecting it
     into the ArcRuleSet. This will make the contained files directly
     available through the rule system, where the fetchFiles() system
     can find them. This is the preferred solution.
   */
  log("FOUND archive rule: dir=" + arc->dirHash.toString() +
      " arc=" + arc->arcHash.toString());

  try
    {
      DirPtr arcDir = addDirFile(out, arc->dirHash, path);
      ptr->arcRules->addArchive(arc->arcHash, arc->dirHash, arcDir,
                                arc->ruleString);
    }
  catch(std::exception &e)
    {
      /* If the dirfile loading fails for whatever reason (perhaps the
         dirfile is not available anywhere), then fall back to doing a
         "blind" unpack.
       */
      log("FAILED loading dirHash=" + arc->dirHash.toString() +
          "\n   Error message: " + std::string(e.what()) +
          "\n   Reverting to blind unpack");
      blinds.insert(HDValue(arc->arcHash, path));
    }
}