def diff_files_patch_vendor(self): if len(self.cpv.diff_files): for f1, f2 in self.cpv.diff_files: if f1.slink != f2.slink: self.cpv.diff_slink_files.append(f2) continue if f1.sha1 == f2.sha1: self.cpv.diff_info_files.append(f2) continue if f2.name in self.cpv.ignore_names: self.cpv.FL_2_isolated_files.append(f2) cn.file2file( f2.path, os.path.join(self.ota_path, "vendor", f2.rela_path)) continue sys.stderr.write("Generating patch file for %-99s\r" % f2.spath) temp_p_file = tempfile.mktemp(".p.tmp") if not cn.get_bsdiff(f1, f2, temp_p_file): self.cpv.FL_2_isolated_files.append(f2) cn.file2file( f2.path, os.path.join(self.ota_path, "vendor", f2.rela_path)) cn.remove_path(temp_p_file) continue p_path = os.path.join(self.ota_path, "patch", "vendor", f2.rela_path + ".p") p_spath = p_path.replace(self.ota_path, "/tmp", 1).replace("\\", "/") cn.file2file(temp_p_file, p_path, move=True) self.patch_check_script_list.append( (f2.spath, f1.sha1, f2.sha1)) self.patch_do_script_list.append( (f2.spath, f2.sha1, len(f2), f1.sha1, p_spath)) cn.clean_line()
def unpack_img(self, img_path, is_new, is_vendor=False): oon, sov = self.pars_init(is_new, is_vendor) print("\nUnpacking %s Rom's %s.img..." % (oon, sov)) if cn.is_win(): spath = cn.extract_img(img_path) cn.remove_path(img_path) else: spath = cn.mount_img(img_path) return spath
def clean_temp(): print("\nCleaning temp files...") for d in os.listdir(tempfile.gettempdir()): if d.startswith("GOTAPGS_"): if not cn.is_win(): for mdir in ("system_", "vendor_"): os.system("sudo umount %s > /dev/null" % os.path.join(tempfile.gettempdir(), d, mdir)) cn.remove_path(os.path.join(tempfile.gettempdir(), d))
def clean_temp(): print("\nCleaning temp files...") for d in os.listdir(tempfile.gettempdir()): if d.startswith("GOTAPGS_"): if not cn.is_win(): for mdir in ("system_", "vendor_"): mount_path = os.path.join(tempfile.gettempdir(), d, mdir) os.system( "mountpoint -q {0} && sudo umount {0}".format( mount_path)) cn.remove_path(os.path.join(tempfile.gettempdir(), d))
def unpack_dat(self, px_path, is_new, is_vendor=False): oon, sov = self.pars_init(is_new, is_vendor) if os.path.exists(os.path.join(px_path, "%s.new.dat.br" % sov)): print("\nUnpacking %s Rom's %s.new.dat.br..." % (oon, sov)) cn.extract_br(os.path.join(px_path, "%s.new.dat.br" % sov)) print("\nUnpacking %s Rom's %s.new.dat..." % (oon, sov)) px_img = cn.extract_sdat( os.path.join(px_path, "%s.transfer.list" % sov), os.path.join(px_path, "%s.new.dat" % sov), os.path.join(px_path, "%s.img" % sov)) cn.remove_path(os.path.join(px_path, "%s.new.dat.br" % sov)) cn.remove_path(os.path.join(px_path, "%s.new.dat" % sov)) return px_img
def diff_files_patch(self): # init # 哈希相同但信息不同的文件 self.cps.diff_info_files = [] # 符号链接指向不同的文件 self.cps.diff_slink_files = [] # 卡刷时直接替换(而不是打补丁)的文件(名) self.cps.ignore_names = { "build.prop", "recovery-from-boot.p", "install-recovery.sh", "backuptool.functions", "backuptool.sh" } if self.pt_flag: self.cpv.diff_info_files = [] self.cpv.diff_slink_files = [] self.cpv.ignore_names = set() cn.mkdir(os.path.join(self.ota_path, "patch")) # fifter system_diff_files_mp = self._diff_files_patch_system_fifter() if self.pt_flag: vendor_diff_files_mp = self._diff_files_patch_vendor_fifter() else: vendor_diff_files_mp = list() get_bsdiff_list(system_diff_files_mp + vendor_diff_files_mp) for f1, f2, temp_p_file in system_diff_files_mp: if os.path.exists(temp_p_file) and os.stat(temp_p_file).st_size: p_path = os.path.join(self.ota_path, "patch", "system", f2.rela_path + ".p") p_spath = p_path.replace(self.ota_path, "/tmp", 1).replace("\\", "/") cn.file2file(temp_p_file, p_path, move=True) self.patch_check_script_list_sp.append( (f2.spath, f1.sha1, f2.sha1)) self.patch_do_script_list_sp.append( (f2.spath, f2.sha1, f1.sha1, p_spath)) else: print("Failed to generate patch file for %s!" % f1.spath) self.cps.FL_2_isolated_files.append(f2) cn.file2file( f2.path, os.path.join(self.ota_path, "system", f2.rela_path)) cn.remove_path(temp_p_file) for f1, f2, temp_p_file in vendor_diff_files_mp: if os.path.exists(temp_p_file) and os.stat(temp_p_file).st_size: p_path = os.path.join(self.ota_path, "patch", "vendor", f2.rela_path + ".p") p_spath = p_path.replace(self.ota_path, "/tmp", 1).replace("\\", "/") cn.file2file(temp_p_file, p_path, move=True) self.patch_check_script_list_sp.append( (f2.spath, f1.sha1, f2.sha1)) self.patch_do_script_list_sp.append( (f2.spath, f2.sha1, f1.sha1, p_spath)) else: print("Failed to generate patch file for %s!" % f1.spath) self.cpv.FL_2_isolated_files.append(f2) cn.file2file( f2.path, os.path.join(self.ota_path, "vendor", f2.rela_path)) cn.remove_path(temp_p_file) # write lines to updater self.us.blank_line() self.us.ui_print("Unpack Patch Files ...") self.us.package_extract_dir("patch", "/tmp/patch") self.us.package_extract_dir("bin", "/tmp/bin") self.us.add("chmod 0755 /tmp/bin/bspatch") self.us.blank_line() self.us.ui_print("Check Files ...") for arg in self.patch_check_script_list_sp: # 差异文件patch check self.us.apply_patch_check_sp(*arg) self.us.blank_line() self.us.ui_print("Patch Files ...") for arg in self.patch_do_script_list_sp: # 差异文件patch self.us.apply_patch_sp(*arg) self.us.blank_line() self.us.delete_recursive("/tmp/patch") self.us.delete_recursive("/tmp/bin")