gst-uninstalled: De-dedup before prepending to an env var
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Apr 2019 10:02:36 +0000 (15:32 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Apr 2019 10:02:36 +0000 (15:32 +0530)
Helps us avoid breaching the maximum length limit for env var values
on Windows.

gst-uninstalled.py

index 982988a0100e399160392f633fce9538bf0fb735..03b9416f9651e887168f7ba8950ab0175939d86b 100755 (executable)
@@ -44,7 +44,12 @@ def stringify(o):
     raise AssertionError('Object {!r} must be a string or a list'.format(o))
 
 def prepend_env_var(env, var, value):
-    env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
+    env_val = env.get(var, '')
+    val = os.pathsep + value + os.pathsep
+    # Don't add the same value twice
+    if val in env_val or env_val.startswith(value + os.pathsep):
+        return
+    env[var] = val + env_val
     env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)