recovery 差分升级包制作超时

我们在对android系统升级的时候,可以减少升级包的大小,只升级差异部分,也就是差分包升级,相关的描述可以参考:http://blog.csdn.net/csdn66_2016/article/details/70256757

    我们在对两个不同的文件进行差分的时候,使用到了两个工具,分别是imgdiffbsdiff,通过这两个工具产生差异部分的patch,升级的时候打patch即可。这两个工具有什么区别呢,我们看看py中是怎么样区别的:

build/tools/releasetools/common.py:

 

DIFF_PROGRAM_BY_EXT = {
    ".gz" : "imgdiff",
    ".zip" : ["imgdiff", "-z"],
    ".jar" : ["imgdiff", "-z"],
    ".apk" : ["imgdiff", "-z"],
    ".img" : "imgdiff",
    }

class Difference(object):
  def __init__(self, tf, sf, diff_program=None):
    self.tf = tf
    self.sf = sf
    self.patch = None
    self.diff_program = diff_program

  def ComputePatch(self):
    """Compute the patch (as a string of data) needed to turn sf into
    tf.  Returns the same tuple as GetPatch()."""

    tf = self.tf
    sf = self.sf

    if self.diff_program:
      diff_program = self.diff_program
    else:
      ext = os.path.splitext(tf.name)[1]
      diff_program = DIFF_PROGRAM_BY_EXT.get(ext, "bsdiff")

    基本上明白了,针对gz zip jar apk img这种压缩的格式,我们使用imgdiff工具来生成patch,否则我们使用bsdiff工具,这两个工具,有不同的针对性,imgdiff对压缩格式的文件效率更高,普通的不带格式的文件bsdiff更合适,我们姑且这么理解。

 

    之前有个客户在制作差分包的时候失败了,后来看了下,发现是有两个300M+的文件在差分,好像提示超时了,然后我写了个sh,看看这两个文件的差分到底需要多久:

 

date
imgdiff   file_old   file_new  file_patch
date

    结果过了30+分钟之后,生成了file_patch

    我们看看,这个common.py中定义的超时时间:

  def ComputePatch(self):
    """Compute the patch (as a string of data) needed to turn sf into
    tf.  Returns the same tuple as GetPatch()."""
    ..........................
    try:
      ptemp = tempfile.NamedTemporaryFile()
      if isinstance(diff_program, list):
        cmd = copy.copy(diff_program)
      else:
        cmd = [diff_program]
      cmd.append(stemp.name)
      cmd.append(ttemp.name)
      cmd.append(ptemp.name)
      p = Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      err = []
      def run():
        _, e = p.communicate()
        if e:
          err.append(e)
      th = threading.Thread(target=run)
      th.start()
      th.join(timeout=300)   # 5 mins
      if th.is_alive():
        print "WARNING: diff command timed out"
        p.terminate()
        th.join(5)
        if th.is_alive():
          p.kill()
          th.join()

    这里默认的5分钟超时,那么当imgdiff大于5分钟的时候,就无法差分升级成功了,如果差分失败了,就需要修改这里的超时时间。

    说个后话,用300M+的文件去差分升级,也是醉了,还不如直接整包升级得了。

原文地址:https://www.cnblogs.com/codeking100/p/10338661.html