def check_path_collision(package, pkgList): """This function will check for collision of paths in a package with the paths of packages in pkgList. The return value will be the list containing the paths that collide.""" create_static = ctx.get_option("create_static") create_debug = ctx.config.values.build.generatedebug ar_suffix = ctx.const.ar_file_suffix debug_suffix = ctx.const.debug_file_suffix collisions = [] for pinfo in package.files: for pkg in pkgList: if pkg is package: continue for path in pkg.files: # if pinfo.path is a subpath of path.path like # the example below. path.path is marked as a # collide. Exp: # pinfo.path: /usr/share # path.path: /usr/share/doc if (create_static and path.path.endswith(ar_suffix)) or ( create_debug and path.path.endswith(debug_suffix) ): # don't throw collision error for these files. # we'll handle this in gen_files_xml.. continue if util.subpath(pinfo.path, path.path): collisions.append(path.path.rstrip("/")) ctx.ui.debug(_("Path %s belongs in multiple packages") % path.path) return collisions
def unpack_file_cond(self, pred, target_dir, archive_root=''): """Unpack/Extract files according to predicate function pred: filename -> bool unpacks stuff into target_dir and only extracts files from archive_root, treating it as the archive root""" zip_obj = self.zip_obj for info in zip_obj.infolist(): if pred(info.filename): # check if condition holds # below code removes that, so we find it here is_dir = info.filename.endswith('/') # calculate output file name if archive_root == '': outpath = info.filename else: # change archive_root if util.subpath(archive_root, info.filename): outpath = util.removepathprefix(archive_root, info.filename) else: continue # don't extract if not under ofile = os.path.join(target_dir, outpath) if is_dir: # this is a directory if not os.path.isdir(ofile): os.makedirs(ofile) perm = info.external_attr perm &= 0xFFFF0000 perm >>= 16 perm |= 0x00000100 os.chmod(ofile, perm) continue # check that output dir is present util.ensure_dirs(os.path.dirname(ofile)) # remove output file we might be overwriting. # (also check for islink? for broken symlinks...) if os.path.isfile(ofile) or os.path.islink(ofile): os.remove(ofile) if info.external_attr == self.symmagic: if os.path.isdir(ofile): # A rare case, the file used to be a dir, # now it is a symlink! shutil.rmtree(ofile) target = zip_obj.read(info.filename) os.symlink(target, ofile) else: perm = info.external_attr perm &= 0x08FF0000 perm >>= 16 perm |= 0x00000100 info.filename = outpath zip_obj.extract(info, target_dir) os.chmod(ofile, perm)
def unpack_dir_flat(self, path, target_dir): self.unpack_file_cond(lambda f: util.subpath(path, f), target_dir, path)