recovery 差分升級包制作超時【轉】


本文轉載自:https://blog.csdn.net/csdn66_2016/article/details/73800349

  我們在對android系統升級的時候,可以減少升級包的大小,只升級差異部分,也就是差分包升級,相關的描述可以參考:http://blog.csdn.net/csdn66_2016/article/details/70256757

    我們在對兩個不同的文件進行差分的時候,使用到了兩個工具,分別是imgdiff與bsdiff,通過這兩個工具產生差異部分的patch,升級的時候打patch即可。這兩個工具有什么區別呢,我們看看py中是怎么樣區別的:

build/tools/releasetools/common.py:

 

[python]  view plain  copy
 
  1. DIFF_PROGRAM_BY_EXT = {  
  2.     ".gz" : "imgdiff",  
  3.     ".zip" : ["imgdiff", "-z"],  
  4.     ".jar" : ["imgdiff", "-z"],  
  5.     ".apk" : ["imgdiff", "-z"],  
  6.     ".img" : "imgdiff",  
  7.     }  
  8.   
  9. class Difference(object):  
  10.   def __init__(self, tf, sf, diff_program=None):  
  11.     self.tf = tf  
  12.     self.sf = sf  
  13.     self.patch = None  
  14.     self.diff_program = diff_program  
  15.   
  16.   def ComputePatch(self):  
  17.     """Compute the patch (as a string of data) needed to turn sf into 
  18.     tf.  Returns the same tuple as GetPatch()."""  
  19.   
  20.     tf = self.tf  
  21.     sf = self.sf  
  22.   
  23.     if self.diff_program:  
  24.       diff_program = self.diff_program  
  25.     else:  
  26.       ext = os.path.splitext(tf.name)[1]  
  27.       diff_program = DIFF_PROGRAM_BY_EXT.get(ext, "bsdiff")  

 

 

    基本上明白了,針對gz zip jar apk img這種壓縮的格式,我們使用imgdiff工具來生成patch,否則我們使用bsdiff工具,這兩個工具,有不同的針對性,imgdiff對壓縮格式的文件效率更高,普通的不帶格式的文件bsdiff更合適,我們姑且這么理解。

 

    之前有個客戶在制作差分包的時候失敗了,后來看了下,發現是有兩個300M+的文件在差分,好像提示超時了,然后我寫了個sh,看看這兩個文件的差分到底需要多久:

 

[plain]  view plain  copy
 
  1. date  
  2. imgdiff   file_old   file_new  file_patch  
  3. date  

 

    結果過了30+分鍾之后,生成了file_patch

    我們看看,這個common.py中定義的超時時間:

 

[python]  view plain  copy
 
  1. def ComputePatch(self):  
  2.   """Compute the patch (as a string of data) needed to turn sf into 
  3.   tf.  Returns the same tuple as GetPatch()."""  
  4.   ..........................  
  5.   try:  
  6.     ptemp = tempfile.NamedTemporaryFile()  
  7.     if isinstance(diff_program, list):  
  8.       cmd = copy.copy(diff_program)  
  9.     else:  
  10.       cmd = [diff_program]  
  11.     cmd.append(stemp.name)  
  12.     cmd.append(ttemp.name)  
  13.     cmd.append(ptemp.name)  
  14.     p = Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)  
  15.     err = []  
  16.     def run():  
  17.       _, e = p.communicate()  
  18.       if e:  
  19.         err.append(e)  
  20.     th = threading.Thread(target=run)  
  21.     th.start()  
  22.     th.join(timeout=300)   # 5 mins  
  23.     if th.is_alive():  
  24.       print "WARNING: diff command timed out"  
  25.       p.terminate()  
  26.       th.join(5)  
  27.       if th.is_alive():  
  28.         p.kill()  
  29.         th.join()  

 

    這里默認的5分鍾超時,那么當imgdiff大於5分鍾的時候,就無法差分升級成功了,如果差分失敗了,就需要修改這里的超時時間。

    說個后話,用300M+的文件去差分升級,也是醉了,還不如直接整包升級得了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM