From 6649f1d3e8852b778807adfe750d8f5e51f3daf4 Mon Sep 17 00:00:00 2001 From: Peter G Date: Tue, 18 Jan 2022 14:53:47 +0100 Subject: [PATCH 1/4] [pm_apply] patch outside the loop --- src/tools/pm_apply | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 91d5aa8a..592dd7b8 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -98,17 +98,14 @@ mangle_libpath() { log found=0 + sedcmd="" + # look for lines to replace, if found add pattern to sed commad for p in $candidates; do - totl_lines=$(grep -c "^\+\+\+" "$PATCH_PATH") cand_lines=$(grep -c "^\+\+\+ [^/]*$p" "$PATCH_PATH") if [ $cand_lines -eq 0 ]; then continue # nothing found, try next else found=$(( $found + $cand_lines )) - if [ $totl_lines -ne $cand_lines ]; then - # if there are several references in the patch file our mangling might do too much and cause the patch to fail. - log "WARNING: mixed patch, conversion might not work" - fi fi log "found: ${p}, replacing libpath references" # prepare the replacement pattern @@ -117,22 +114,22 @@ mangle_libpath() { pr=$(printf '%s' "$p" | sed 's@/usr/lib64/@/usr/lib/@') elif [ $SYS_BITNESS -eq 64 ]; then pr=$(printf '%s' "$p" | sed 's@/usr/lib/@/usr/lib64/@') - fi - # doit - if [ $found -eq $cand_lines ]; then # first run in loop - mkdir -p "$PM_PATCH_BACKUP_DIR" - patch_edited_path="$PM_PATCH_BACKUP_DIR"/"$PATCH_EDITED_NAME" - printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) \ - | cat - "$PATCH_PATH" > "$patch_edited_path" - fi - sed -i "s@^\+\+\+ \([^/]*\)$p@+++ \1$pr@;s@^--- \([^/]*\)$p@--- \1$pr@" "$patch_edited_path" || failure || true # patch the Patch + fi + # append to the start so we can separate using ';' + sedcmd="s@^\+\+\+ \([^/]*\)$p@+++ \1$pr@;s@^--- \([^/]*\)$p@--- \1$pr@;$sedcmd" done if [ $found -eq 0 ]; then log log "OK, found nothing to convert." log else - log + # doit + mkdir -p "$PM_PATCH_BACKUP_DIR" + patch_edited_path="$PM_PATCH_BACKUP_DIR"/"$PATCH_EDITED_NAME" + printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) \ + | cat - "$PATCH_PATH" > "$patch_edited_path" + sed -i "$sedcmd" "$patch_edited_path" || failure || true # patch the Patch + log "OK, replaced $found libpath references and created: $patch_edited_path" log # set the patch to apply to the new one: From 19884683ee154409efdf3780d30fca1e74f59ea8 Mon Sep 17 00:00:00 2001 From: Peter G Date: Tue, 18 Jan 2022 17:39:09 +0100 Subject: [PATCH 2/4] fixup! [pm_apply] patch outside the loop --- src/tools/pm_apply | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 592dd7b8..930d47c1 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -130,6 +130,7 @@ mangle_libpath() { | cat - "$PATCH_PATH" > "$patch_edited_path" sed -i "$sedcmd" "$patch_edited_path" || failure || true # patch the Patch + log log "OK, replaced $found libpath references and created: $patch_edited_path" log # set the patch to apply to the new one: From 5ddbdd5f98c39e71a8222f7ad84d6a19b0c93494 Mon Sep 17 00:00:00 2001 From: Peter G Date: Tue, 18 Jan 2022 17:55:30 +0100 Subject: [PATCH 3/4] fixup! fixup! [pm_apply] patch outside the loop --- src/tools/pm_apply | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 930d47c1..ffd97786 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -123,11 +123,12 @@ mangle_libpath() { log "OK, found nothing to convert." log else - # doit + # create new patch file and add a note to it mkdir -p "$PM_PATCH_BACKUP_DIR" patch_edited_path="$PM_PATCH_BACKUP_DIR"/"$PATCH_EDITED_NAME" printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) \ | cat - "$PATCH_PATH" > "$patch_edited_path" + # now execute the mangling proper sed -i "$sedcmd" "$patch_edited_path" || failure || true # patch the Patch log From ff50ee4ed783e979de2d06d8316998cb7badbd39 Mon Sep 17 00:00:00 2001 From: olf Date: Tue, 18 Jan 2022 19:39:37 +0100 Subject: [PATCH 4/4] pm_apply: Use sed streamingly & some beautifying --- src/tools/pm_apply | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index ffd97786..6696f871 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -99,42 +99,47 @@ mangle_libpath() { found=0 sedcmd="" - # look for lines to replace, if found add pattern to sed commad + # look for lines to convert, if some are found add pattern to sed scriptlet for p in $candidates; do cand_lines=$(grep -c "^\+\+\+ [^/]*$p" "$PATCH_PATH") if [ $cand_lines -eq 0 ]; then continue # nothing found, try next - else - found=$(( $found + $cand_lines )) fi - log "found: ${p}, replacing libpath references" - # prepare the replacement pattern + found=$(( $found + $cand_lines )) + log "Converting library path reference $p $cand_lines times" + + # prepare the path replacement pattern pr="" if [ $SYS_BITNESS -eq 32 ]; then pr=$(printf '%s' "$p" | sed 's@/usr/lib64/@/usr/lib/@') elif [ $SYS_BITNESS -eq 64 ]; then pr=$(printf '%s' "$p" | sed 's@/usr/lib/@/usr/lib64/@') - fi - # append to the start so we can separate using ';' + else + failure + fi + # append at the front so ';' can be easily used for separation sedcmd="s@^\+\+\+ \([^/]*\)$p@+++ \1$pr@;s@^--- \([^/]*\)$p@--- \1$pr@;$sedcmd" done + if [ $found -eq 0 ]; then log log "OK, found nothing to convert." log else - # create new patch file and add a note to it mkdir -p "$PM_PATCH_BACKUP_DIR" patch_edited_path="$PM_PATCH_BACKUP_DIR"/"$PATCH_EDITED_NAME" - printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) \ - | cat - "$PATCH_PATH" > "$patch_edited_path" - # now execute the mangling proper - sed -i "$sedcmd" "$patch_edited_path" || failure || true # patch the Patch + # create mangled patch file and add a note to it + printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) \ + | cat - "$PATCH_PATH" | sed "$sedcmd" > "$patch_edited_path" # patch the Patch + if [ $? -ne 0 ]; then + failure + fi + log - log "OK, replaced $found libpath references and created: $patch_edited_path" + log "OK, converted $found library path references and created: $patch_edited_path" log - # set the patch to apply to the new one: + # set the patch path to the new one: PATCH_PATH="$patch_edited_path" fi fi @@ -149,7 +154,6 @@ verify_text_patch() { log $PATCH_EXEC -p 1 -d "$ROOT_DIR" --dry-run < "$PATCH_PATH" 2>&1 | tee -a "$PM_LOG_FILE" - if [ $? -ne 0 ]; then failure fi