From 556b2d8aee2e642030dca384c5902de74b33988a Mon Sep 17 00:00:00 2001 From: olf Date: Thu, 30 Dec 2021 06:39:25 +0100 Subject: [PATCH 1/4] Prepare for multiple conversion runs This still ought be functionally equivalent to the original version as of PM 3.2.0: please test! --- src/tools/pm_apply | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 43e50248..0ee66ff1 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -104,7 +104,7 @@ mangle_libpath() { totl_lines=$(grep -c "^+++" "$PATCH_PATH") cand_lines=$(grep -c "^+++ $p" "$PATCH_PATH") if [ $cand_lines -eq 0 ]; then - continue # nothing found, try next + continue # nothing found, try next else found=$(( $found + $cand_lines )) if [ $totl_lines -ne $cand_lines ]; then @@ -112,12 +112,9 @@ mangle_libpath() { log "WARNING: mixed patch, conversion might not work" fi fi - - patch_edited_path="$PM_PATCH_BACKUP_DIR"/"$PATCH_EDITED_NAME" log "found: ${p}, replacing libpath references" - - mkdir -p "$PM_PATCH_BACKUP_DIR" - # prepare the pattern + + # prepare the replacement pattern pr="" if [ $SYS_BITNESS -eq 32 ]; then pr=$(printf '%s' "$p" | sed 's@/usr/lib64/@/usr/lib/@') @@ -125,23 +122,26 @@ mangle_libpath() { pr=$(printf '%s' "$p" | sed 's@/usr/lib/@/usr/lib64/@') fi # doit - printf '#\n# patch converted to %sbit library paths from its original by Patchmanager >= 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) > "$patch_edited_path" + 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) > "$patch_edited_path" sed "s@^+++ $p@+++ $pr@;s@^--- $p@--- $pr@" "$PATCH_PATH" >> "$patch_edited_path" if [ $? -ne 0 ]; then failure fi - log - log "OK, conversion produced: $patch_edited_path" - log - # set the patch to apply to the new one: - PATCH_PATH="$patch_edited_path" - return + break done if [ $found -eq 0 ]; then log - log "OK, found nothing to convert" + log "OK, found nothing to convert." + log + else + log + log "OK, replaced $found paths and created: $patch_edited_path" log - fi + # set the patch to apply to the new one: + PATCH_PATH="$patch_edited_path" + fi fi } From dda3f1a32c11778ed6d775aef382635bec519447 Mon Sep 17 00:00:00 2001 From: olf Date: Thu, 30 Dec 2021 06:42:37 +0100 Subject: [PATCH 2/4] Enhance log output --- src/tools/pm_apply | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 0ee66ff1..750f1640 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -137,7 +137,7 @@ mangle_libpath() { log else log - log "OK, replaced $found paths and created: $patch_edited_path" + log "OK, replaced $found libpath references and created: $patch_edited_path" log # set the patch to apply to the new one: PATCH_PATH="$patch_edited_path" From b1fea730ff99dc3969c1e3eea73ed83ce0ec3eeb Mon Sep 17 00:00:00 2001 From: olf Date: Thu, 30 Dec 2021 07:15:46 +0100 Subject: [PATCH 3/4] Do convert multiple libpath references This is on top of MR #221, so each step can be well tested, separately --- src/tools/pm_apply | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 750f1640..298b14f9 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -122,14 +122,16 @@ mangle_libpath() { pr=$(printf '%s' "$p" | sed 's@/usr/lib/@/usr/lib64/@') fi # 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) > "$patch_edited_path" - sed "s@^+++ $p@+++ $pr@;s@^--- $p@--- $pr@" "$PATCH_PATH" >> "$patch_edited_path" + 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) > "$patch_edited_path" + cat "$PATCH_PATH" >> "$patch_edited_path" + fi + sed -i "s@^+++ $p@+++ $pr@;s@^--- $p@--- $pr@" "$patch_edited_path" # patch the Patch if [ $? -ne 0 ]; then failure fi - break done if [ $found -eq 0 ]; then log From 2a1f08bfd72ed038f16583c66953a928df0545b8 Mon Sep 17 00:00:00 2001 From: olf Date: Thu, 30 Dec 2021 15:05:42 +0100 Subject: [PATCH 4/4] Simplify code --- src/tools/pm_apply | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/tools/pm_apply b/src/tools/pm_apply index 298b14f9..0d45dfcb 100644 --- a/src/tools/pm_apply +++ b/src/tools/pm_apply @@ -125,13 +125,10 @@ mangle_libpath() { 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) > "$patch_edited_path" - cat "$PATCH_PATH" >> "$patch_edited_path" - fi - sed -i "s@^+++ $p@+++ $pr@;s@^--- $p@--- $pr@" "$patch_edited_path" # patch the Patch - if [ $? -ne 0 ]; then - failure + printf '#\n# Patch converted to %sbit library paths from its original by Patchmanager > 3.1\n# Date: %s\n#\n' $SYS_BITNESS $(date -Iseconds) > "$patch_edited_path" \ + | cat - "$PATCH_PATH" > "$patch_edited_path" fi + sed -i "s@^+++ $p@+++ $pr@;s@^--- $p@--- $pr@" "$patch_edited_path" || failure || true # patch the Patch done if [ $found -eq 0 ]; then log