diff --git a/subprojects/gstreamer/gst/gst_private.h b/subprojects/gstreamer/gst/gst_private.h index 0ed3d07ee9..1471fb0e30 100644 --- a/subprojects/gstreamer/gst/gst_private.h +++ b/subprojects/gstreamer/gst/gst_private.h @@ -520,6 +520,7 @@ struct _GstClockEntryImpl }; char * priv_gst_get_relocated_libgstreamer (void); +gint priv_gst_count_directories (const char *filepath); G_END_DECLS #endif /* __GST_PRIVATE_H__ */ diff --git a/subprojects/gstreamer/gst/gstpluginloader-win32.c b/subprojects/gstreamer/gst/gstpluginloader-win32.c index d6af200892..20644e16b6 100644 --- a/subprojects/gstreamer/gst/gstpluginloader-win32.c +++ b/subprojects/gstreamer/gst/gstpluginloader-win32.c @@ -451,74 +451,6 @@ error: return FALSE; } -static int -count_directories (const char *filepath) -{ - int i = 0; - char *tmp; - gsize len; - - g_return_val_if_fail (!g_path_is_absolute (filepath), 0); - - tmp = g_strdup (filepath); - len = strlen (tmp); - - /* ignore UNC share paths entirely */ - if (len >= 3 && G_IS_DIR_SEPARATOR (tmp[0]) && G_IS_DIR_SEPARATOR (tmp[1]) - && !G_IS_DIR_SEPARATOR (tmp[2])) { - GST_WARNING ("found a UNC share path, ignoring"); - return 0; - } - - /* remove trailing slashes if they exist */ - while ( - /* don't remove the trailing slash for C:\. - * UNC paths are at least \\s\s */ - len > 3 && G_IS_DIR_SEPARATOR (tmp[len - 1])) { - tmp[len - 1] = '\0'; - len--; - } - - while (tmp) { - char *dirname, *basename; - len = strlen (tmp); - - if (g_strcmp0 (tmp, ".") == 0) - break; - if (g_strcmp0 (tmp, "/") == 0) - break; - - /* g_path_get_dirname() may return something of the form 'C:.', where C is - * a drive letter */ - if (len == 3 && g_ascii_isalpha (tmp[0]) && tmp[1] == ':' && tmp[2] == '.') - break; - - basename = g_path_get_basename (tmp); - dirname = g_path_get_dirname (tmp); - - if (g_strcmp0 (basename, "..") == 0) { - i--; - } else if (g_strcmp0 (basename, ".") == 0) { - /* nothing to do */ - } else { - i++; - } - - g_clear_pointer (&basename, g_free); - g_clear_pointer (&tmp, g_free); - tmp = dirname; - } - - g_clear_pointer (&tmp, g_free); - - if (i < 0) { - g_critical ("path counting resulted in a negative directory count!"); - return 0; - } - - return i; -} - static gboolean gst_plugin_loader_spawn (GstPluginLoader * loader) { @@ -550,7 +482,7 @@ gst_plugin_loader_spawn (GstPluginLoader * loader) relocated_libgstreamer = priv_gst_get_relocated_libgstreamer (); if (relocated_libgstreamer) { - int plugin_subdir_depth = count_directories (GST_PLUGIN_SUBDIR); + int plugin_subdir_depth = priv_gst_count_directories (GST_PLUGIN_SUBDIR); GST_DEBUG ("found libgstreamer-" GST_API_VERSION " library " "at %s", relocated_libgstreamer); diff --git a/subprojects/gstreamer/gst/gstpluginloader.c b/subprojects/gstreamer/gst/gstpluginloader.c index af9b2121b7..fdc6fbe398 100644 --- a/subprojects/gstreamer/gst/gstpluginloader.c +++ b/subprojects/gstreamer/gst/gstpluginloader.c @@ -460,83 +460,6 @@ gst_plugin_loader_try_helper (GstPluginLoader * loader, gchar * location) return TRUE; } -static int -count_directories (const char *filepath) -{ - int i = 0; - char *tmp; - gsize len; - - g_return_val_if_fail (!g_path_is_absolute (filepath), 0); - - tmp = g_strdup (filepath); - len = strlen (tmp); - -#if defined(G_OS_WIN32) - /* ignore UNC share paths entirely */ - if (len >= 3 && G_IS_DIR_SEPARATOR (tmp[0]) && G_IS_DIR_SEPARATOR (tmp[1]) - && !G_IS_DIR_SEPARATOR (tmp[2])) { - GST_WARNING ("found a UNC share path, ignoring"); - return 0; - } -#endif - - /* remove trailing slashes if they exist */ - while ( -#if defined(G_OS_WIN32) - /* don't remove the trailing slash for C:\. - * UNC paths are at least \\s\s */ - len > 3 -#else - /* don't remove the trailing slash for / */ - len > 1 -#endif - && G_IS_DIR_SEPARATOR (tmp[len - 1])) { - tmp[len - 1] = '\0'; - len--; - } - - while (tmp) { - char *dirname, *basename; - len = strlen (tmp); - - if (g_strcmp0 (tmp, ".") == 0) - break; - if (g_strcmp0 (tmp, "/") == 0) - break; -#if defined(G_OS_WIN32) - /* g_path_get_dirname() may return something of the form 'C:.', where C is - * a drive letter */ - if (len == 3 && g_ascii_isalpha (tmp[0]) && tmp[1] == ':' && tmp[2] == '.') - break; -#endif - - basename = g_path_get_basename (tmp); - dirname = g_path_get_dirname (tmp); - - if (g_strcmp0 (basename, "..") == 0) { - i--; - } else if (g_strcmp0 (basename, ".") == 0) { - /* nothing to do */ - } else { - i++; - } - - g_clear_pointer (&basename, g_free); - g_clear_pointer (&tmp, g_free); - tmp = dirname; - } - - g_clear_pointer (&tmp, g_free); - - if (i < 0) { - g_critical ("path counting resulted in a negative directory count!"); - return 0; - } - - return i; -} - static gboolean gst_plugin_loader_spawn (GstPluginLoader * loader) { @@ -574,7 +497,7 @@ gst_plugin_loader_spawn (GstPluginLoader * loader) relocated_libgstreamer = priv_gst_get_relocated_libgstreamer (); if (relocated_libgstreamer) { - int plugin_subdir_depth = count_directories (GST_PLUGIN_SUBDIR); + int plugin_subdir_depth = priv_gst_count_directories (GST_PLUGIN_SUBDIR); GST_DEBUG ("found libgstreamer-" GST_API_VERSION " library " "at %s", relocated_libgstreamer); diff --git a/subprojects/gstreamer/gst/gstregistry.c b/subprojects/gstreamer/gst/gstregistry.c index 1b69d13f4f..8a62cca6ce 100644 --- a/subprojects/gstreamer/gst/gstregistry.c +++ b/subprojects/gstreamer/gst/gstregistry.c @@ -1626,6 +1626,74 @@ priv_gst_get_relocated_libgstreamer (void) return dir; } +int +priv_gst_count_directories (const char *filepath) +{ + int i = 0; + char *tmp; + gsize len; + + g_return_val_if_fail (!g_path_is_absolute (filepath), 0); + + tmp = g_strdup (filepath); + len = strlen (tmp); + + /* ignore UNC share paths entirely */ + if (len >= 3 && G_IS_DIR_SEPARATOR (tmp[0]) && G_IS_DIR_SEPARATOR (tmp[1]) + && !G_IS_DIR_SEPARATOR (tmp[2])) { + GST_WARNING ("found a UNC share path, ignoring"); + return 0; + } + + /* remove trailing slashes if they exist */ + while ( + /* don't remove the trailing slash for C:\. + * UNC paths are at least \\s\s */ + len > 3 && G_IS_DIR_SEPARATOR (tmp[len - 1])) { + tmp[len - 1] = '\0'; + len--; + } + + while (tmp) { + char *dirname, *basename; + len = strlen (tmp); + + if (g_strcmp0 (tmp, ".") == 0) + break; + if (g_strcmp0 (tmp, "/") == 0) + break; + + /* g_path_get_dirname() may return something of the form 'C:.', where C is + * a drive letter */ + if (len == 3 && g_ascii_isalpha (tmp[0]) && tmp[1] == ':' && tmp[2] == '.') + break; + + basename = g_path_get_basename (tmp); + dirname = g_path_get_dirname (tmp); + + if (g_strcmp0 (basename, "..") == 0) { + i--; + } else if (g_strcmp0 (basename, ".") == 0) { + /* nothing to do */ + } else { + i++; + } + + g_clear_pointer (&basename, g_free); + g_clear_pointer (&tmp, g_free); + tmp = dirname; + } + + g_clear_pointer (&tmp, g_free); + + if (i < 0) { + g_critical ("path counting resulted in a negative directory count!"); + return 0; + } + + return i; +} + #ifndef GST_DISABLE_REGISTRY /* Unref all plugins marked 'cached', to clear old plugins that no * longer exist. Returns %TRUE if any plugins were removed */