From aa7c031bf4ea8c0b3defa7943a9202939628471e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20A=C5=9F=C4=B1c=C4=B1?= Date: Sun, 13 Jun 2010 14:40:11 +0000 Subject: [PATCH] archive: Add callback parameter to ArchiveTar.unpack_dir Install related stuff is moved from archive.py to atomicoperations.py by using a callback function. --- pisi/archive.py | 25 +++++-------------------- pisi/package.py | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/pisi/archive.py b/pisi/archive.py index 93a41e6b..c59da3d7 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -224,7 +224,7 @@ class ArchiveTar(ArchiveBase): super(ArchiveTar, self).unpack(target_dir, clean_dir) self.unpack_dir(target_dir) - def unpack_dir(self, target_dir): + def unpack_dir(self, target_dir, callback=None): rmode = "" self.tar = None if self.type == 'tar': @@ -252,23 +252,9 @@ class ArchiveTar(ArchiveBase): uid = os.getuid() gid = os.getgid() - install_tar_path = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar) for tarinfo in self.tar: - # Installing packages (especially shared libraries) is a - # bit tricky. You should also change the inode if you - # change the file, cause the file is opened allready and - # accessed. Removing and creating the file will also - # change the inode and will do the trick (in fact, old - # file will be deleted only when its closed). - # - # Also, tar.extract() doesn't write on symlinks... Not any - # more :). - if self.file_path.startswith(install_tar_path): - if os.path.isfile(tarinfo.name) or os.path.islink(tarinfo.name): - try: - os.unlink(tarinfo.name) - except OSError, e: - ctx.ui.warning(e) + if callback: + callback(tarinfo, extracted=False) self.tar.extract(tarinfo) @@ -287,9 +273,8 @@ class ArchiveTar(ArchiveBase): else: os.lchown(tarinfo.name, uid, gid) - # Added for package-manager - if tarinfo.name.endswith(".desktop"): - ctx.ui.notify(pisi.ui.desktopfile, desktopfile=tarinfo.name) + if callback: + callback(tarinfo, extracted=True) try: if oldwd: diff --git a/pisi/package.py b/pisi/package.py index 366cf543..b63ebac8 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -96,11 +96,34 @@ class Package: self.impl.unpack_dir(dir, outdir) def extract_install(self, outdir): + def callback(tarinfo, extracted): + if not extracted: + # Installing packages (especially shared libraries) is a + # bit tricky. You should also change the inode if you + # change the file, cause the file is opened allready and + # accessed. Removing and creating the file will also + # change the inode and will do the trick (in fact, old + # file will be deleted only when its closed). + # + # Also, tar.extract() doesn't write on symlinks... Not any + # more :). + if os.path.isfile(tarinfo.name) or os.path.islink(tarinfo.name): + try: + os.unlink(tarinfo.name) + except OSError, e: + ctx.ui.warning(e) + + else: + # Added for package-manager + if tarinfo.name.endswith(".desktop"): + ctx.ui.notify(pisi.ui.desktopfile, desktopfile=tarinfo.name) + + if self.impl.has_file(ctx.const.install_tar_lzma): lzmafile = os.path.join(ctx.config.tmp_dir(), ctx.const.install_tar_lzma) self.extract_file(ctx.const.install_tar_lzma, ctx.config.tmp_dir()) tar = archive.ArchiveTar(lzmafile, 'tarlzma', False, False) - tar.unpack_dir(outdir) + tar.unpack_dir(outdir, callback=callback) # cleanup install.tar.lzma and install.tar after installing if os.path.exists(lzmafile):