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

def zeroinstall::zerostore::manifest::_copy_files (   alg,
  wanted,
  source,
  target 
) [private]

Scan for files under 'source'. For each one:
If it is in wanted and has the right details (or they can be fixed; e.g. mtime),
then copy it into 'target'.
If it's not in wanted, warn and skip it.
On exit, wanted contains only files that were not found.

Definition at line 321 of file manifest.py.

00321                                             :
      """Scan for files under 'source'. For each one:
      If it is in wanted and has the right details (or they can be fixed; e.g. mtime),
      then copy it into 'target'.
      If it's not in wanted, warn and skip it.
      On exit, wanted contains only files that were not found."""
      from logging import warn
      dir = ''
      for line in alg.generate_manifest(source):
            if line[0] == 'D':
                  type, name = line.split(' ', 1)
                  assert name.startswith('/')
                  dir = name[1:]
                  path = dir
            elif line[0] == 'S':
                  type, actual_digest, actual_size, name = line.split(' ', 3)
                  path = os.path.join(dir, name)
            else:
                  assert line[0] in 'XF'
                  type, actual_digest, actual_mtime, actual_size, name = line.split(' ', 4)
                  path = os.path.join(dir, name)
            try:
                  required_details = wanted.pop(path)
            except KeyError:
                  warn("Skipping file not in manifest: '%s'", path)
                  continue
            if required_details[0] != type:
                  raise zerostore.BadDigest("Item '%s' has wrong type!" % path)
            if type == 'D':
                  os.mkdir(os.path.join(target, path))
            elif type in 'XF':
                  required_type, required_digest, required_mtime, required_size = required_details
                  if required_size != actual_size:
                        raise SafeException("File '%s' has wrong size (%s bytes, but should be "
                                        "%s according to manifest)" %
                                        (path, actual_size, required_size))
                  required_mtime = int(required_mtime)
                  dest_path = os.path.join(target, path)
                  if type == 'X':
                        mode = 0555
                  else:
                        mode = 0444
                  copy_with_verify(os.path.join(source, path),
                              dest_path,
                              mode,
                              alg,
                              required_digest)
                  os.utime(dest_path, (required_mtime, required_mtime))
            elif type == 'S':
                  required_type, required_digest, required_size = required_details
                  if required_size != actual_size:
                        raise SafeException("Symlink '%s' has wrong size (%s bytes, but should be "
                                        "%s according to manifest)" %
                                        (path, actual_size, required_size))
                  symlink_target = os.readlink(os.path.join(source, path))
                  symlink_digest = alg.new_digest()
                  symlink_digest.update(symlink_target)
                  if symlink_digest.hexdigest() != required_digest:
                        raise SafeException("Symlink '%s' has wrong target (digest should be "
                                    "%s according to manifest)" % (path, required_digest))
                  dest_path = os.path.join(target, path)
                  os.symlink(symlink_target, dest_path)
            else:
                  raise SafeException("Unknown manifest type %s for '%s'" % (type, path))

class HashLibAlgorithm(Algorithm):


Generated by  Doxygen 1.6.0   Back to index