String substitution within a patch

I’d like to patch a package (matomo) to use a different path to find some of its files. I got some advice that ended up not working, but found the following patch worked:

diff --git a/plugins/GeoIp2/LocationProvider/GeoIp2.php b/plugins/GeoIp2/LocationProvider/GeoIp2.php
index 6116b52c66..5b41ae10c1 100644
--- a/plugins/GeoIp2/LocationProvider/GeoIp2.php
+++ b/plugins/GeoIp2/LocationProvider/GeoIp2.php
@@ -124,7 +124,7 @@ abstract class GeoIp2 extends LocationProvider
      */
     public static function getPathForGeoIpDatabase($filename)
     {
-        return StaticContainer::get('path.geoip2') . $filename;
+        return "/var/lib/geoip-databases/" . $filename;
     }
 
     /**

I added it to services.matomo.package.patches and it seems to work as planned. The question is, how can I avoid hard-coding this path? It’s present in my configuration and used elsewhere for nginx and updater configs. I tried writeText with the whole patch as a string, but some subtle whitespace differences between the file I start with and the one in the store make the patch not apply.

Surround the variable with @ like this:

and then include the patch like this:

4 Likes