diff --git a/c_glib/arrow-glib/file-system.cpp b/c_glib/arrow-glib/file-system.cpp index 0fa8deb3186..36080f1cbdb 100644 --- a/c_glib/arrow-glib/file-system.cpp +++ b/c_glib/arrow-glib/file-system.cpp @@ -723,6 +723,26 @@ garrow_file_system_register_type(const gchar *type_name, GType gtype, GError **e return TRUE; } +/** + * garrow_file_system_ensure_finalized: + * + * Finalize all registered Arrow C++ file system implementations. + * + * Call this function during application shutdown, after file system + * operations have finished and streams have been closed. Do not use + * file system APIs after this call. + * + * The caller is responsible for synchronizing this call with other + * file system activity. + * + * Since: 27.0.0 + */ +void +garrow_file_system_ensure_finalized(void) +{ + arrow::fs::EnsureFinalized(); +} + /** * garrow_file_system_create: * @uri: An URI to specify file system with options. If you only have an diff --git a/c_glib/arrow-glib/file-system.h b/c_glib/arrow-glib/file-system.h index 666271956df..87a8d4d7e41 100644 --- a/c_glib/arrow-glib/file-system.h +++ b/c_glib/arrow-glib/file-system.h @@ -104,6 +104,10 @@ GARROW_AVAILABLE_IN_27_0 gboolean garrow_file_system_register_type(const gchar *type_name, GType gtype, GError **error); +GARROW_AVAILABLE_IN_27_0 +void +garrow_file_system_ensure_finalized(void); + GARROW_AVAILABLE_IN_3_0 GArrowFileSystem * garrow_file_system_create(const gchar *uri, GError **error); diff --git a/c_glib/test/test-file-system.rb b/c_glib/test/test-file-system.rb index 281f3d0804f..ccc5728766c 100644 --- a/c_glib/test/test-file-system.rb +++ b/c_glib/test/test-file-system.rb @@ -58,4 +58,27 @@ def test_unrelated_type end end end + + sub_test_case(".ensure_finalized") do + def test_create_after_finalization + # Finalization affects the whole process, so isolate it from the test runner. + pid = spawn(RbConfig.ruby, "-e", <<-SCRIPT) +require "gi" +require "test/unit/assertions" + +include Test::Unit::Assertions + +Gio = GI.load("Gio") +Arrow = GI.load("Arrow") + +Arrow::FileSystem.create("mock://") +Arrow::FileSystem.ensure_finalized +assert_raise(Arrow::Error::Invalid) do + Arrow::FileSystem.create("mock://") +end + SCRIPT + _, status = Process.wait2(pid) + assert_predicate(status, :success?) + end + end end