Skip to content

Debugging Patches

olf edited this page Jan 23, 2023 · 5 revisions

Manually applying Patches

Understand that neither the patch utility or any of the Patches are distributed by the Patchmanager app. Patchmanager merely manages the installation (from the Web Catalog, RPM-Patches are installed per package management infrastructure of SailfishOS), settings (e.g., enabled / disabled) and activation of Patches by using the patch command to apply the patch file a Patch contains.
(This is so explicitly mentioned because people keep asking how to use the “patch tool” as if it was a component of Patchmanager. It is not! patch is a standard UNIX tool completely unrelated to Patchmanager. There are literally 36 years worth of examples out there on the web on how patch works, use your favourite search engine to learn more.)

Obtaining a patch file from a Patch

  • From an installed Patch from the Web Catalog

  • From an installed Patch RPM

  • Downloading and extracting from a Patch in the Web Catalog

  • Downloading and extracting from a Patch RPM

Manually activating Patches

To test whether a patch file of a Patch works (note the --dry-run option switch, and that there is no need to become root user per devel-su for this):

patch -p1 -d / --dry-run -i /usr/share/patchmanager/patches/(whatever_patch_directory)/unified_diff.patch

If errors are reported, the issue is likely caused by the unified_diff.patch file, hence you might report this issue to the author of that patch, or try to fix it yourself.

If this initial test seems to work, you can apply the patch file manually (i.e., same command without --dry-run ):

devel-su patch -p1 -d / -i /usr/share/patchmanager/patches/<patch-name>/unified_diff.patch

NOTE this will actually change system files on disk. If you activate a Patch by enabling it in Patchmanager, it does not change the patched files on disk. This means if you apply patch files this way, you have to take care to undo the change, especially when you intend to enable this Patch in Patchmanager later.

To remove / "unapply" an applied patch file, use (same as applying but with -R ):

devel-su patch -p1 -R -d / -i /usr/share/patchmanager/patches/<patch-name>/unified_diff.patch

Again, this can only "unapply" patch files you have applied manually using the method above, NOT try to deactivate Patches activated by Patchmanager this way (because Patchmanager does not alter the original files, only copies of them).

Summary

By testing this way you are:

  • changing system files on disk, and are responsible on undoing the change them or restoring the original file.
  • can easily make some apps or the whole home screen, even the whole system not work [???Need to be rectified???]
  • get to keep any broken pieces [???Need to be rectified???]
  • and naturally, using the patch utility instead of Patchmananger does not magically make a patch file work: If a Patch does not apply, it fails for a reason and no amount of “devel-su copy paste random things from the internet” will make it work.

If trying a patch file fails, you must clean up the mess left behind before you try again!

Failing when applying a patch file usually leaves behind these files:

filename
filename.orig
filename.rej

filename contains the changed file up to the point where the patch failed (so it contains what was successfully changed). filename.orig is the unmodified, original file. filename.rej contains the part of the patch file which failed to apply. If you can read the diff format, you can try to apply those changes manually using an editor.


Original source: https://forum.sailfishos.org/t/bugs-in-patches-for-patchmanager/8553/14 ff.