Change DELTA_FS type deltas to be created with relative pathnames and remove their... 97/280997/4
authorAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Tue, 6 Sep 2022 13:31:42 +0000 (15:31 +0200)
committerAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Mon, 26 Sep 2022 12:55:37 +0000 (14:55 +0200)
/run/upgrade-sysroot directory

Change-Id: I58348748e5359047bd587a6a7cf34af570665940

mk_delta/common/bin/CreatePatch.py
mk_delta/common/bin/mk_part_delta.sh

index 99399df..f8dacb1 100755 (executable)
@@ -6,7 +6,6 @@ import filecmp
 import shutil
 import subprocess
 import re
-import ntpath
 import zipfile
 import datetime
 import hashlib
@@ -76,7 +75,7 @@ COMMON_BIN_PATH = "../../common/bin/"
 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"
@@ -305,15 +304,10 @@ def ensure_dir_exists(path):
 
 
 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":
@@ -335,7 +329,7 @@ def Update_Attr(RequestedPath, Type, File_Attributes, Sym_Attributes):
        # 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:
@@ -672,7 +666,6 @@ def SS_Generate_Delta(PART_NAME, BASE_OLD, Old_files, Old_dirs, BASE_NEW, New_fi
 
        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)
@@ -785,22 +778,23 @@ def SS_Generate_Delta(PART_NAME, BASE_OLD, Old_files, Old_dirs, BASE_NEW, New_fi
                        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
@@ -808,20 +802,17 @@ def SS_Generate_Delta(PART_NAME, BASE_OLD, Old_files, Old_dirs, BASE_NEW, New_fi
                        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))
 
@@ -842,13 +833,7 @@ def SS_Generate_Delta(PART_NAME, BASE_OLD, Old_files, Old_dirs, BASE_NEW, New_fi
                        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)
@@ -858,9 +843,10 @@ def SS_Generate_Delta(PART_NAME, BASE_OLD, Old_files, Old_dirs, BASE_NEW, New_fi
        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)
index a3ad1bf..3f1f49e 100755 (executable)
@@ -94,13 +94,13 @@ fn_mk_attribute()
 
        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}
@@ -114,10 +114,11 @@ fn_mk_attribute()
        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)"
 }
@@ -394,7 +395,6 @@ fn_mk_delta_fs()
        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
 
@@ -402,32 +402,24 @@ fn_mk_delta_fs()
        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"
                ;;
 
        * )
@@ -436,8 +428,8 @@ fn_mk_delta_fs()
                ;;
        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