registry: skip Rust dep builddirs when searching for plugins recursively
authorTim-Philipp Müller <tim@centricular.com>
Sat, 9 Apr 2022 20:07:43 +0000 (21:07 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 30 Apr 2022 08:48:22 +0000 (08:48 +0000)
These artefacts confuse the plugin scanner and may cause noisy warnings
(and slow down things).

Fixes https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/68

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2146>

subprojects/gstreamer/gst/gstregistry.c

index 47d6065..3c43ceb 100644 (file)
@@ -1213,13 +1213,41 @@ gst_registry_scan_plugin_file (GstRegistryScanContext * context,
 }
 
 static gboolean
-is_blacklisted_directory (const gchar * dirent)
+skip_directory (const gchar * parent_path, const gchar * dirent)
 {
+  const gchar *target;
+
   /* hotdoc private folder can contain many files and it slows down
    * the discovery for nothing */
   if (g_str_has_prefix (dirent, "hotdoc-private-"))
     return TRUE;
 
+  /* Rust build dirs which may contain artefacts we should skip, can be
+   * /target/{debug,release} or /target/{arch}/{debug,release} */
+  target = strstr (parent_path, "/target/");
+
+  /* On Windows both forward and backward slashes may be used */
+#ifdef G_OS_WIN32
+  if (target == NULL)
+    target = strstr (parent_path, "\\target\\");
+#endif
+
+  if (target != NULL) {
+    if (g_str_has_suffix (target + 7, "/debug")
+#ifdef G_OS_WIN32
+        || g_str_has_suffix (target + 7, "\\debug")
+        || g_str_has_suffix (target + 7, "\\release")
+#endif
+        || g_str_has_suffix (target + 7, "/release")) {
+      if (dirent[0] == '.'
+          || strcmp (dirent, "build") == 0
+          || strcmp (dirent, "deps") == 0
+          || strcmp (dirent, "incremental") == 0) {
+        return TRUE;
+      }
+    }
+  }
+
   if (G_LIKELY (dirent[0] != '.'))
     return FALSE;
 
@@ -1262,7 +1290,7 @@ gst_registry_scan_path_level (GstRegistryScanContext * context,
     }
 
     if (file_status.st_mode & S_IFDIR) {
-      if (G_UNLIKELY (is_blacklisted_directory (dirent))) {
+      if (G_UNLIKELY (skip_directory (path, dirent))) {
         GST_TRACE_OBJECT (context->registry, "ignoring %s directory", dirent);
         g_free (filename);
         continue;