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

def zeroinstall::zerostore::Store::check_manifest_and_rename (   self,
  required_digest,
  tmp,
  extract = None 
)

Check that tmp[/extract] has the required_digest.
On success, rename the checked directory to the digest and,
if self.public, make the whole tree read-only.
@raise BadDigest: if the input directory doesn't match the given digest

Definition at line 138 of file __init__.py.

00138                                                                                :
            """Check that tmp[/extract] has the required_digest.
            On success, rename the checked directory to the digest and,
            if self.public, make the whole tree read-only.
            @raise BadDigest: if the input directory doesn't match the given digest"""
            # Should we make private stores read-only too?
            if extract:
                  extracted = os.path.join(tmp, extract)
                  if not os.path.isdir(extracted):
                        raise Exception('Directory %s not found in archive' % extract)
            else:
                  extracted = tmp

            import manifest
            alg, required_value = manifest.splitID(required_digest)
            actual_digest = alg.getID(manifest.add_manifest_file(extracted, alg))
            if actual_digest != required_digest:
                  raise BadDigest('Incorrect manifest -- archive is corrupted.\n'
                              'Required digest: %s\n'
                              'Actual digest: %s\n' %
                              (required_digest, actual_digest))

            final_name = os.path.join(self.dir, required_digest)
            if os.path.isdir(final_name):
                  raise Exception("Item %s already stored." % final_name)
            if extract:
                  os.rename(os.path.join(tmp, extract), final_name)
                  os.rmdir(tmp)
            else:
                  os.rename(tmp, final_name)

            if self.public:
                  import stat
                  for dirpath, dirnames, filenames in os.walk(final_name):
                        for item in ['.'] + filenames:
                              full = os.path.join(dirpath, item)
                              info = os.lstat(full)
                              if not stat.S_ISLNK(info.st_mode):
                                    os.chmod(full, info.st_mode & ~stat.S_IWRITE)


class Stores(object):


Generated by  Doxygen 1.6.0   Back to index