import shutil
import subprocess
import re
-import ntpath
import zipfile
import datetime
import hashlib
DIFF_UTIL = "/usr/local/bin/ss_bsdiff"
DIFFPATCH_UTIL = "/usr/local/bin/ss_bspatch"
#ZIPUTIL = "p7zip "
-ZIPUTIL = "7z -mf=off a system.7z "
+ZIPUTIL = "7z -mf=off a "
NEW_FILES_PATH = "run/upgrade-sysroot"
NEW_FILES_ZIP_NAME = "system.7z"
SYMLINK_TYPE = "SYM"
def path_leaf(path):
- head, tail = ntpath.split(path) # This is for windows?? Recheck
+ head, tail = os.path.split(path)
return tail
-def path_head(path):
- head, tail = ntpath.split(path)
- return head
-
-
# Creating Diff between OLD and NEW attribute files v12
def Diff_AttrFiles(ATTR_OLD, ATTR_NEW, ATTR_FILE):
if GenerateDiffAttr == "FALSE":
# Full File Path should MATCH
if GenerateDiffAttr == "FALSE":
return
- FilePath = '"/' + RequestedPath + '"'
+ FilePath = '"' + RequestedPath + '"'
#print ('FilePath - %s'% (FilePath))
with open(AttributeFile) as f:
for line in f:
for new_file in NewList:
R_Flag = 'FALSE'
- DirPathNew = path_head(new_file)
FileNameNew = path_leaf(new_file)
DiffSize = 0
winning_patch_sz = os.path.getsize(BASE_NEW + '/' + new_file)
Del_Cnt = Del_Cnt + 1
logging.debug(' Dir Deleted- %s' % src_file)
+ try:
+ ensure_dir_exists(NEW_FILES_PATH)
+ except FileExistsError as exc:
+ logging.error('Directory %s used by this script is already an existing file' % NEW_FILES_PATH)
+ raise exc
+
for elt in files_new:
- dst_file = BASE_NEW + '/' + elt
- newfiles_dest_path = 'run/upgrade-sysroot/'
- try:
- ensure_dir_exists(newfiles_dest_path)
- except FileExistsError as exc:
- logging.error('Directory %s used by this script is already an existing file' % newfiles_dest_path)
- raise exc
+ dst_file = os.path.join(BASE_NEW, elt)
+ destpath = os.path.join(NEW_FILES_PATH, elt)
+
if os.path.islink(dst_file):
patch = os.readlink(dst_file)
logging.debug(' File New Links %s' % elt)
Partition_Doc_SymLinks.write('SYM:NEW:%s:%s\n' % (elt, patch))
# What if this is only a new sym link and folder already exists??? Should recheck
- destpath = newfiles_dest_path + elt
- if not os.path.exists(path_head(destpath)):
- os.makedirs(path_head(destpath))
+ if not os.path.exists(os.path.dirname(destpath)):
+ os.makedirs(os.path.dirname(destpath))
logging.info('New SymLink - Adding missing Dir')
Update_Attr(elt, "SYM", File_Attributes, Sym_Attributes)
Sym_New_Cnt = Sym_New_Cnt + 1
patch = New_hardlinks[elt]
logging.debug('File new hardlink %s' % elt)
Partition_Doc_HardLinks.write('HARD:NEW:%s:%s\n' %(elt, patch))
- destpath = newfiles_dest_path + elt
- if not os.path.exists(path_head(destpath)):
- os.makedirs(path_head(destpath))
+ if not os.path.exists(os.path.dirname(destpath)):
+ os.makedirs(os.path.dirname(destpath))
logging.info('New hardlink - Adding missing Dir')
Hard_New_Cnt += 1
elif os.path.isdir(dst_file): # We create just empty directory here
- destpath = newfiles_dest_path + elt
if not os.path.exists(destpath):
os.makedirs(destpath)
logging.debug(' File New Dir %s' % destpath)
New_Cnt = New_Cnt + 1
else:
New_Cnt = New_Cnt + 1
- destpath = newfiles_dest_path + elt
destdir = os.path.dirname(destpath)
logging.debug('New files - %s ==> %s' % (dst_file, destdir))
Update_Attr(elt, "FILE", File_Attributes, Sym_Attributes)
for elt in Dir_Added:
- newfiles_dest_path = 'run/upgrade-sysroot/'
- try:
- ensure_dir_exists(newfiles_dest_path)
- except FileExistsError as exc:
- logging.error('Directory %s used by this script is already an existing file' % newfiles_dest_path)
- raise exc
- destpath = newfiles_dest_path + elt
+ destpath = os.path.join(NEW_FILES_PATH, elt)
if not os.path.exists(destpath):
os.makedirs(destpath)
logging.debug(' DirList New Dir %s' % destpath)
print 'Compressing New files'
if (New_Cnt > 0 or Sym_New_Cnt > 0):
WorkingDir = os.getcwd()
- os.chdir(os.getcwd() + "/" + NEW_FILES_PATH)
+ os.chdir(os.path.join(os.getcwd(), NEW_FILES_PATH))
logging.info('Curr Working Dir - %s' % os.getcwd())
- os.system(ZIPUTIL + NEW_FILES_PATH + " >> " + LOGFILE)
+ log_path = os.path.join(WorkingDir, LOGFILE)
+ os.system(ZIPUTIL + NEW_FILES_ZIP_NAME + " . " + " >> " + log_path)
shutil.move(NEW_FILES_ZIP_NAME, WorkingDir + "/" + OUT_DIR)
# New file size?? cos, we extract system.7z from delta.tar and then proceed with decompression
SS_UpdateSize(WorkingDir + "/" + OUT_DIR + "/" + NEW_FILES_ZIP_NAME, WorkingDir + "/" + OUT_DIR + "/" + NEW_FILES_ZIP_NAME)
echo "Attribute generation for ${TARGET} [START] $(date +%T)"
- sudo find ./${BASE_DIR_OLD} -type f -printf '"/%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V1_ATTR_FILE}
- sudo find ./${BASE_DIR_OLD} -type l -printf '"/%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
- sudo find ./${BASE_DIR_OLD} -type d -printf '"/%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
+ sudo find ./${BASE_DIR_OLD} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V1_ATTR_FILE}
+ sudo find ./${BASE_DIR_OLD} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
+ sudo find ./${BASE_DIR_OLD} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
- sudo find ./${BASE_DIR_NEW} -type f -printf '"/%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V2_ATTR_FILE}
- sudo find ./${BASE_DIR_NEW} -type l -printf '"/%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
- sudo find ./${BASE_DIR_NEW} -type d -printf '"/%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
+ sudo find ./${BASE_DIR_NEW} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V2_ATTR_FILE}
+ sudo find ./${BASE_DIR_NEW} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
+ sudo find ./${BASE_DIR_NEW} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
################ Change user and group permission from '0' to '0000' ############
sed -i 's/: 0/:0000/g' ${V1_ATTR_FILE}
sed -i 's/: /:0/g' ${V2_ATTR_FILE}
################ Change ":./old" to "/" ############
- sed -i "s/:.\/${BASE_DIR_OLD}\//:\//" ${V1_ATTR_FILE}
- sed -i "s/:.\/${BASE_DIR_OLD}/:\//" ${V1_ATTR_FILE}
- sed -i "s/:.\/${BASE_DIR_NEW}\//:\//" ${V2_ATTR_FILE}
- sed -i "s/:.\/${BASE_DIR_NEW}/:\//" ${V2_ATTR_FILE}
+ sed -i "s/:.\/${BASE_DIR_OLD}\//:/" ${V1_ATTR_FILE}
+ sed -i "s/:.\/${BASE_DIR_OLD}/:/" ${V1_ATTR_FILE}
+
+ sed -i "s/:.\/${BASE_DIR_NEW}\//:/" ${V2_ATTR_FILE}
+ sed -i "s/:.\/${BASE_DIR_NEW}/:/" ${V2_ATTR_FILE}
echo "Attribute generation for ${TARGET} [END] $(date +%T)"
}
DEBUG_DELTA=debug_${DELTA}
#CFG_XML=${PART_NAME}_FS.xml
- FAKE_ROOT=run/upgrade-sysroot
BASE_OLD=${PART_NAME}_OLD
BASE_NEW=${PART_NAME}_NEW
case "${PART_NAME}" in
"rootfs" )
EXCLUDE_FILES="lost+found dev proc tmp var sys csa"
- TGT_MNT_PNT=${FAKE_ROOT}
-
;;
"ramdisk1" | "ramdisk" )
EXCLUDE_FILES="lost+found dev proc tmp sys"
- TGT_MNT_PNT=${FAKE_ROOT}/mnt/initrd
;;
"ramdisk2" | "ramdisk-recovery" )
EXCLUDE_FILES="lost+found"
- TGT_MNT_PNT=${FAKE_ROOT}/mnt/initrd-recovery
;;
"user" )
EXCLUDE_FILES="lost+found"
- TGT_MNT_PNT=${FAKE_ROOT}/opt/usr
;;
"system-data" )
EXCLUDE_FILES="lost+found"
- TGT_MNT_PNT=${FAKE_ROOT}/opt
;;
"kernel" | "boot" )
EXCLUDE_FILES=""
- TGT_MNT_PNT=${FAKE_ROOT}/boot
;;
"hal" )
EXCLUDE_FILES=""
- TGT_MNT_PNT="${FAKE_ROOT}/hal"
;;
* )
;;
esac
- MNT_PNT_OLD=${BASE_OLD}/${TGT_MNT_PNT}
- MNT_PNT_NEW=${BASE_NEW}/${TGT_MNT_PNT}
+ MNT_PNT_OLD=${BASE_OLD}/
+ MNT_PNT_NEW=${BASE_NEW}/
fn_gen_metadata
fn_mk_delta_fs_core