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

def zeroinstall::zerostore::manifest::copy_with_verify (   src,
  dest,
  mode,
  alg,
  required_digest 
)

Copy path src to dest, checking that the contents give the right digest.
dest must not exist. New file is created with a mode of 'mode & umask'.
@param src: source filename
@type src: str
@param dest: target filename
@type dest: str
@param mode: target mode
@type mode: int
@param alg: algorithm to generate digest
@type alg: L{Algorithm}
@param required_digest: expected digest value
@type required_digest: str
@raise BadDigest: the contents of the file don't match required_digest

Definition at line 150 of file manifest.py.

00150                                                            :
      """Copy path src to dest, checking that the contents give the right digest.
      dest must not exist. New file is created with a mode of 'mode & umask'.
      @param src: source filename
      @type src: str
      @param dest: target filename
      @type dest: str
      @param mode: target mode
      @type mode: int
      @param alg: algorithm to generate digest
      @type alg: L{Algorithm}
      @param required_digest: expected digest value
      @type required_digest: str
      @raise BadDigest: the contents of the file don't match required_digest"""
      src_obj = file(src)
      dest_fd = os.open(dest, os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode)
      digest = alg.new_digest()
      while True:
            data = src_obj.read(256)
            if not data: break
            digest.update(data)
            while data:
                  written = os.write(dest_fd, data)
                  assert written >= 0
                  data = data[written:]
      actual = digest.hexdigest()
      if actual == required_digest: return
      os.unlink(dest)
      raise BadDigest(("Copy failed: file '%s' has wrong digest (may have been tampered with)\n"
                   "Excepted: %s\n"
                   "Actual:   %s") % (src, required_digest, actual))

def verify(root, required_digest = None):


Generated by  Doxygen 1.6.0   Back to index