patchLoc = '%s/%s' % (OUT_DIR, patchName)
logging.debug(' File Differ %s %s' % (src_file, dst_file))
SS_UpdateSize(src_file, dst_file)
- if SUPPORT_CONTAINERS == "TRUE":
- if src_file.endswith('.zip') and dst_file.endswith('.zip'):
- FORMAT = "ZIP"
- Partition_Doc.write('DIFF:ZIP:%s:%s:%s:%s:%s/\n' % (elt, elt, hash_file(src_file), hash_file(dst_file), patchName))
- compute_containerdelta(src_file, dst_file, FORMAT, OUT_DIR+'/'+patchName, Partition_Doc)
- elif src_file.endswith('.tpk') and dst_file.endswith('.tpk'):
- FORMAT = "TPK"
- Partition_Doc.write('DIFF:TPK:%s:%s:%s:%s:%s/\n' % (elt, elt, hash_file(src_file), hash_file(dst_file), patchName))
- compute_containerdelta(src_file, dst_file, FORMAT, OUT_DIR+'/'+patchName, Partition_Doc)
- else:
- FORMAT = "REG"
- Partition_Doc.write('DIFF:REG:%s:%s:%s:%s:%s\n' % (elt, elt, hash_file(src_file), hash_file(dst_file), patchName))
- subprocess.call([DIFF_UTIL,src_file,dst_file,patchLoc])
+
+ FORMAT = "REG"
+ ret = subprocess.call([DIFF_UTIL,src_file,dst_file,patchLoc])
+ if ret is not 0:
+ logging.debug('Failed to create diff %d %s %s\n' % (ret, src_file, dst_file))
+ files_new.append(elt)
+ Diff_Cnt = Diff_Cnt - 1
else:
- FORMAT = "REG"
- ret = subprocess.call([DIFF_UTIL,src_file,dst_file,patchLoc])
- if ret is not 0:
- logging.debug('Failed to create diff %d %s %s\n' % (ret, src_file, dst_file))
- files_new.append(elt)
- Diff_Cnt = Diff_Cnt - 1
- else:
- Partition_Doc.write('DIFF:REG:%s:%s:%s:%s:%s\n' % (elt, elt, hash_file(src_file), hash_file(dst_file), patchName))
+ Partition_Doc.write('DIFF:REG:%s:%s:%s:%s:%s\n' % (elt, elt, hash_file(src_file), hash_file(dst_file), patchName))
Update_Attr(elt, "FILE", File_Attibutes, Sym_Attibutes)
#Both differ but they are of diff types
Move_Cnt = Move_Cnt + 1
Diff_Cnt = Diff_Cnt - 1
Partition_Doc.write('MOVE:REG:%s:%s:%s\n' % (elt[1], elt[0], hash_file(src_file)))
- elif SUPPORT_CONTAINERS == "TRUE":
- if src_file.endswith('.zip') and dst_file.endswith('.zip'):
- FORMAT = "ZIP"
- Partition_Doc.write('DIFF:ZIP:%s:%s:%s:%s:%s/\n' % (elt[1], elt[0], hash_file(src_file), hash_file(dst_file), patchName))
- compute_containerdelta(src_file, dst_file, FORMAT, OUT_DIR+'/'+patchName, Partition_Doc)
- elif src_file.endswith('.tpk') and dst_file.endswith('.tpk'):
- FORMAT = "TPK"
- Partition_Doc.write('DIFF:TPK:%s:%s:%s:%s:%s/\n' % (elt[1], elt[0], hash_file(src_file), hash_file(dst_file), patchName))
- compute_containerdelta(src_file, dst_file, FORMAT, OUT_DIR+'/'+patchName, Partition_Doc)
- else:
- FORMAT = "REG"
- Partition_Doc.write('DIFF:REG:%s:%s:%s:%s:%s\n' % (elt[1], elt[0], hash_file(src_file), hash_file(dst_file), patchName))
- subprocess.call([DIFF_UTIL,src_file,dst_file,patchLoc])
else:
FORMAT = "REG"
ret = subprocess.call([DIFF_UTIL,src_file,dst_file,patchLoc])
#Base directory should be system
print 'Compressing New files'
- if (New_Cnt > 0):
+ if (New_Cnt > 0 or Sym_New_Cnt > 0):
WorkingDir = os.getcwd()
os.chdir(os.getcwd()+"/"+NEW_FILES_PATH)
logging.info('Curr Working Dir - %s' % os.getcwd())
def IsSymlink(info):
return (info.external_attr >> 16) == 0120777
-
-def compute_containerdelta(src_file, dst_file, FORMAT, patchName, Partition_Doc):
-
- a_apk = src_file
- b_apk = dst_file
- a_folder = 'temp_a'
- b_folder = 'temp_b'
-
- g_output_dir = patchName
-
- logging.info('Uncompressing Containers... [%s][%s]' % (src_file, dst_file))
- logging.info('Out Dir -%s' %(g_output_dir))
- ensure_dir_exists(a_folder)
- zipf = zipfile.ZipFile(a_apk, 'r');
- zipf.extractall(a_folder)
- zipf.close()
-
- ensure_dir_exists(b_folder)
- zipf = zipfile.ZipFile(b_apk, 'r');
- zipf.extractall(b_folder)
-
-
- symlinks = []
- for info in zipf.infolist():
- basefilename = info.filename[7:]
- if IsSymlink(info):
- symlinks.append(info.filename)
- os.remove(b_folder+'/'+info.filename)
- zipf.close()
-
- a_files, a_dirs = Get_Files(a_folder)
- b_files, b_dirs = Get_Files(b_folder)
-
- logging.info('Going from %d files %d files' % (len(a_files), len(b_files)))
-
- # First let's fill up these categories
- C_files_new = []
- C_files_removed = []
- C_files_changed = []
- C_files_unchanged = []
-
- # What files appear in B but not in A?
- for elt in b_files:
- if elt not in a_files:
- #if not elt.endswith('.so'):
- C_files_new.append(elt)
-
- # What files appear in A but not in B?
- for elt in a_files:
- if elt not in b_files:
- C_files_removed.append(elt)
-
- # What files have changed contents but not name/path?
- for elt in b_files:
- if elt in a_files:
- if os.path.islink(a_folder+'/'+elt) or os.path.islink(b_folder+'/'+elt):
- print 'links - skip'
- elif not filecmp.cmp(a_folder+'/'+elt, b_folder+'/'+elt):
- C_files_changed.append(elt)
- else:
- C_files_unchanged.append(elt)
-
-
- print('%d new files' % len(C_files_new))
- print('%d removed files' % len(C_files_removed))
- print('%d files changed' % len(C_files_changed))
- print('%d files unchanged' % len(C_files_unchanged))
-
- # temp dir where we're assembling the patch
- ensure_dir_exists(g_output_dir)
-
- unique_fileid = 0
- toc = open(g_output_dir+'/PATCH.txt','w')
- print("writing diff'ed changed files...")
-
- for elt in C_files_changed:
- dst_file = b_folder+'/'+elt
- src_file = a_folder+'/'+elt
- patchName = (DIFF_PREFIX+'%d_%s_'+PART_NAME+DIFF_SUFFIX) % (unique_fileid, path_leaf(elt))
- patchLoc = '%s/%s' % (g_output_dir, patchName)
- #print('src - %s dest -%s patch -%s' % (src_file ,dst_file,patchLoc))
- subprocess.call([DIFF_UTIL,src_file ,dst_file,patchLoc])
- toc.write('c%d|%s|%s\n' % (unique_fileid, elt, patchName))
- unique_fileid = unique_fileid + 1
-
- for elt in C_files_unchanged:
- dst_file = b_folder+'/'+elt
- src_file = a_folder+'/'+elt
- #print('Same Files src - %s dest -%s' % (src_file ,dst_file))
- toc.write('s%d|%s\n' % (unique_fileid, elt))
- unique_fileid = unique_fileid + 1
-
- #Create NEW TPK with empty data for below files and NEW files
- shutil.copy2(b_apk, g_output_dir)
-
- #May b for host??
- #temp_apk = '../'+g_output_dir+'/'+b_apk
- temp_apk = '../'+g_output_dir+'/'+path_leaf(b_apk)
-
- for elt in C_files_changed:
- dst_file = b_folder+'/'+elt
- #print dst_file
- open(dst_file, 'w').close()
-
- for elt in C_files_unchanged:
- dst_file = b_folder+'/'+elt
- open(dst_file, 'w').close()
-
- WorkingDir = os.getcwd()
- os.chdir(WorkingDir+"/"+b_folder)
-
- #for elt in files_changed:
- # subprocess.call(['zip', temp_apk, elt]) # confirm ZIP options, extra fields etc.. jus zip it, shd do all at once.. else time taking
-
- #for elt in files_unchanged:
- # subprocess.call(['zip', temp_apk, elt])
-
- subprocess.call(['zip','-ryq', temp_apk, '*'])
- os.chdir(WorkingDir)
- toc.close()
-
- Apply_Container_Delta(path_leaf(a_apk), path_leaf(b_apk), b_apk, a_folder, g_output_dir)
- shutil.rmtree(a_folder)
- shutil.rmtree(b_folder)
-
def NewFiles(src, dest):
print src,dest
subprocess.call(['cp','-rp', src,dest])