def unpack_to_tmp(url, archive_file, mime_type): """Creates a temporary directory and unpacks the archive to it in "unpacked". Permissions are correct for importing into the cache. Returns the tmpdir.""" if not mime_type: mime_type = unpack.type_from_url(url) assert mime_type, "Can't guess MIME type from {url}".format(url = url) tmpdir = tempfile.mkdtemp('-0template') try: # Must be readable to helper process running as 'zeroinst'... old_umask = os.umask(0o022) try: unpack_dir = os.path.join(tmpdir, 'unpacked') os.mkdir(unpack_dir) with open(archive_file, 'rb') as stream: unpack.unpack_archive(url, stream, unpack_dir, type = mime_type, start_offset = 0) manifest.fixup_permissions(unpack_dir) finally: os.umask(old_umask) except: support.ro_rmtree(tmpdir) raise return tmpdir
def assert_manifest(self, required): alg_name = required.split('=', 1)[0] manifest.fixup_permissions(self.tmpdir) sha1 = alg_name + '=' + manifest.add_manifest_file(self.tmpdir, manifest.get_algorithm(alg_name)).hexdigest() self.assertEqual(sha1, required) # Check permissions are sensible for root, dirs, files in os.walk(self.tmpdir): for f in files + dirs: full = os.path.join(root, f) if os.path.islink(full): continue full_mode = os.stat(full).st_mode self.assertEqual(0o444, full_mode & 0o666) # Must be r-?r-?r-?
def assert_manifest(self, required): alg_name = required.split('=', 1)[0] manifest.fixup_permissions(self.tmpdir) sha1 = alg_name + '=' + manifest.add_manifest_file( self.tmpdir, manifest.get_algorithm(alg_name)).hexdigest() self.assertEqual(sha1, required) # Check permissions are sensible for root, dirs, files in os.walk(self.tmpdir): for f in files + dirs: full = os.path.join(root, f) if os.path.islink(full): continue full_mode = os.stat(full).st_mode self.assertEqual(0o444, full_mode & 0o666) # Must be r-?r-?r-?
def local_archive_changed(chooser): model.clear() path = chooser.get_filename() widgets.get_widget('subdirectory_frame').set_sensitive(False) self.destroy_tmp() if not path: return if mime_type.get_active() == 0: type = None else: type = mime_type.get_active_text() archive_url = widgets.get_widget('archive_url') url = archive_url.get_text() if not url: url = 'http://SITE/' + os.path.basename(path) archive_url.set_text(url) start_offset = 0 if not type: if url.endswith('.package'): type = 'Autopackage' else: type = unpack.type_from_url(url) if type == 'Autopackage': # Autopackage isn't a real type. Examine the .package file # and find out what it really is. start_offset, type = autopackage_get_details(path) self.tmpdir = tempfile.mkdtemp('-0publish-gui') try: # Must be readable to helper process running as 'zeroinst'... old_umask = os.umask(0022) try: unpack_dir = os.path.join(self.tmpdir, 'unpacked') os.mkdir(unpack_dir) dialog.window.set_cursor(watch) gtk.gdk.flush() try: unpack.unpack_archive(url, file(path), unpack_dir, type = type, start_offset = start_offset) manifest.fixup_permissions(unpack_dir) finally: dialog.window.set_cursor(None) finally: os.umask(old_umask) except: chooser.unselect_filename(path) self.destroy_tmp() raise iter = model.append(None, ['Everything']) items = os.listdir(unpack_dir) for f in items: model.append(iter, [f]) tree.expand_all() # Choose a sensible default iter = model.get_iter_root() if len(items) == 1 and \ os.path.isdir(os.path.join(unpack_dir, items[0])) and \ items[0] not in ('usr', 'opt', 'bin', 'etc', 'sbin', 'doc', 'var'): iter = model.iter_children(iter) selection.select_iter(iter) self.mime_type = type self.start_offset = start_offset widgets.get_widget('subdirectory_frame').set_sensitive(True)