How to disconnect / unmount from a remote volume using GIO function

Hello all,

I need some help with g_file_unmount_mountable_with_operation(). The documentation says it unmounts a file of type G_FILE_TYPE_MOUNTABLE. But in my application I “mounted” a remote connection to an URI via g_file_mount_enclosing_volume() for a GFile object which I created out of the URI string ftp://localhost:77/. This GFile object is of type G_FILE_TYPE_DIRECTORY which I found out using g_file_query_file_type()… .

My question is now: How can I create a GFile object of type G_FILE_TYPE_MOUNTABLE for the given remote URI so that I can unmount the volume again with g_file_unmount_mountable_with_operation?

When I do the following I get an error saying “Operation is not supported” in the callback later on:

GFile gFile = g_file_new_for_uri("ftp://localhost:77");
g_file_unmount_mountable_with_operation (
    gFile,
    G_MOUNT_UNMOUNT_NONE,
    nullptr,
    nullptr,
    remote_close_callback,
    con
);

What am I missing? Thank you very much for suggestions.

I wonder why there are 6 parameters in the declaration

void
g_file_unmount_mountable_with_operation (
  GFile* file,
  GMountUnmountFlags flags,
  GMountOperation* mount_operation,
  GCancellable* cancellable,
  GAsyncReadyCallback callback,
  gpointer user_data
)

And in the Parameters documentation are explained only 5?

Parameters
    flags	        GMountUnmountFlags
                    Flags affecting the operation.

    mount_operation	GMountOperation
                    A GMountOperation, or NULL to avoid user interaction.
 	                The argument can be NULL.
 	                The data is owned by the caller of the function.

    cancellable	    GCancellable
                    Optional GCancellable object, NULL to ignore.
 	                The argument can be NULL.
 	                The data is owned by the caller of the function.

    callback	    GAsyncReadyCallback
                    A GAsyncReadyCallback to call when the request is satisfied, or NULL.

    user_data	    gpointer
                    The data to pass to callback function.

.
file ....missing documentation...

The instance doesn’t really need any description though

My thought would be to find_enclosing_mount which you can then g_mount_unmount_with_operation

Thank you very much, Zander. That worked for me. :ok_hand:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.