Logo Search packages:      
Sourcecode: zeroinstall-injector version File versions

def zeroinstall::zerostore::manifest::verify (   root,
  required_digest = None 
)

Ensure that directory 'dir' generates the given digest.
For a non-error return:
 - Dir's name must be a digest (in the form "alg=value")
 - The calculated digest of the contents must match this name.
 - If there is a .manifest file, then its digest must also match.
@raise BadDigest: if verification fails.

Definition at line 182 of file manifest.py.

00182                                         :
      """Ensure that directory 'dir' generates the given digest.
      For a non-error return:
       - Dir's name must be a digest (in the form "alg=value")
       - The calculated digest of the contents must match this name.
       - If there is a .manifest file, then its digest must also match.
      @raise BadDigest: if verification fails."""
      if required_digest is None:
            required_digest = os.path.basename(root)
      alg = splitID(required_digest)[0]

      digest = alg.new_digest()
      lines = []
      for line in alg.generate_manifest(root):
            line += '\n'
            digest.update(line)
            lines.append(line)
      actual_digest = alg.getID(digest)

      manifest_file = os.path.join(root, '.manifest')
      if os.path.isfile(manifest_file):
            digest = alg.new_digest()
            digest.update(file(manifest_file).read())
            manifest_digest = alg.getID(digest)
      else:
            manifest_digest = None

      if required_digest == actual_digest == manifest_digest:
            return

      error = BadDigest("Cached item does NOT verify.")
      
      error.detail = " Expected digest: " + required_digest + "\n" + \
                   "   Actual digest: " + actual_digest + "\n" + \
                   ".manifest digest: " + (manifest_digest or 'No .manifest file') + "\n\n"

      if manifest_digest is None:
            error.detail += "No .manifest, so no further details available."
      elif manifest_digest == actual_digest:
            error.detail += "The .manifest file matches the actual contents. Very strange!"
      elif manifest_digest == required_digest:
            import difflib
            diff = difflib.unified_diff(file(manifest_file).readlines(), lines,
                                  'Recorded', 'Actual')
            error.detail += "The .manifest file matches the directory name.\n" \
                        "The contents of the directory have changed:\n" + \
                        ''.join(diff)
      elif required_digest == actual_digest:
            error.detail += "The directory contents are correct, but the .manifest file is wrong!"
      else:
            error.detail += "The .manifest file matches neither of the other digests. Odd."
      raise error

# XXX: Be more careful about the source tree changing under us. In particular, what happens if:
# - A regualar file suddenly turns into a symlink?
# - We find a device file (users can hard-link them if on the same device)
def copy_tree_with_verify(source, target, manifest_data, required_digest):


Generated by  Doxygen 1.6.0   Back to index