archive: Add callback parameter to ArchiveTar.unpack_dir
Install related stuff is moved from archive.py to atomicoperations.py by using a callback function.
This commit is contained in:
+5
-20
@@ -224,7 +224,7 @@ class ArchiveTar(ArchiveBase):
|
|||||||
super(ArchiveTar, self).unpack(target_dir, clean_dir)
|
super(ArchiveTar, self).unpack(target_dir, clean_dir)
|
||||||
self.unpack_dir(target_dir)
|
self.unpack_dir(target_dir)
|
||||||
|
|
||||||
def unpack_dir(self, target_dir):
|
def unpack_dir(self, target_dir, callback=None):
|
||||||
rmode = ""
|
rmode = ""
|
||||||
self.tar = None
|
self.tar = None
|
||||||
if self.type == 'tar':
|
if self.type == 'tar':
|
||||||
@@ -252,23 +252,9 @@ class ArchiveTar(ArchiveBase):
|
|||||||
uid = os.getuid()
|
uid = os.getuid()
|
||||||
gid = os.getgid()
|
gid = os.getgid()
|
||||||
|
|
||||||
install_tar_path = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar)
|
|
||||||
for tarinfo in self.tar:
|
for tarinfo in self.tar:
|
||||||
# Installing packages (especially shared libraries) is a
|
if callback:
|
||||||
# bit tricky. You should also change the inode if you
|
callback(tarinfo, extracted=False)
|
||||||
# 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)
|
|
||||||
|
|
||||||
self.tar.extract(tarinfo)
|
self.tar.extract(tarinfo)
|
||||||
|
|
||||||
@@ -287,9 +273,8 @@ class ArchiveTar(ArchiveBase):
|
|||||||
else:
|
else:
|
||||||
os.lchown(tarinfo.name, uid, gid)
|
os.lchown(tarinfo.name, uid, gid)
|
||||||
|
|
||||||
# Added for package-manager
|
if callback:
|
||||||
if tarinfo.name.endswith(".desktop"):
|
callback(tarinfo, extracted=True)
|
||||||
ctx.ui.notify(pisi.ui.desktopfile, desktopfile=tarinfo.name)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if oldwd:
|
if oldwd:
|
||||||
|
|||||||
+24
-1
@@ -96,11 +96,34 @@ class Package:
|
|||||||
self.impl.unpack_dir(dir, outdir)
|
self.impl.unpack_dir(dir, outdir)
|
||||||
|
|
||||||
def extract_install(self, 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):
|
if self.impl.has_file(ctx.const.install_tar_lzma):
|
||||||
lzmafile = os.path.join(ctx.config.tmp_dir(), 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())
|
self.extract_file(ctx.const.install_tar_lzma, ctx.config.tmp_dir())
|
||||||
tar = archive.ArchiveTar(lzmafile, 'tarlzma', False, False)
|
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
|
# cleanup install.tar.lzma and install.tar after installing
|
||||||
if os.path.exists(lzmafile):
|
if os.path.exists(lzmafile):
|
||||||
|
|||||||
Reference in New Issue
Block a user