Skip to content

Add gio::File, gio::FileEnumerator, gio::FileMonitor, gio::Vfs subclasses #1676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

fbrouille
Copy link
Contributor

Allow custom implementation of gio::Vfs, gio::File, gio::FileEnumerator and gio::FileMonitor

@sdroege
Copy link
Member

sdroege commented Mar 4, 2025

Very interesting, thanks! OOC, what are you planning to implement with this?

Comment on lines 471 to 472
unsafe impl Send for MyFileEnumerator {}
unsafe impl Sync for MyFileEnumerator {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are implemented automatically if possible. Are they not, and why are they required here?

Copy link
Contributor Author

@fbrouille fbrouille Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. It was old code while implementing the tests.


impl MyFileMonitor {
pub async fn tick(&self) {
std::thread::sleep(std::time::Duration::from_millis(10));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is an async function it should probably use an async sleep mechanism. glib::timeout_future() for example

Copy link
Contributor Author

@fbrouille fbrouille Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.parent_is_active()
}

fn get_file_for_path(&self, path: &GString) -> File {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably also need to implement the required pieces to implement gio::File for this to be useful, or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
Initially i through I would have to implement 70+ methods of gio::File, but finally only few ones are required for tests of gio::Vfs subclass, so it is ok.

@sdroege
Copy link
Member

sdroege commented Mar 4, 2025

Just shortly looked over it, will do a proper review one of these days but generally it looks correct.

@fbrouille fbrouille force-pushed the gio_file_subclass branch from 94aacc1 to bbfa6db Compare March 4, 2025 13:03
self.parent_is_active()
}

fn get_file_for_path(&self, path: &GString) -> File {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it take a GString or a PathBuf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path parameter in VfsExt::file_for_path is a &str, so I think it should be a &str.
Another alternative is to change path parameter in VfsExt::file_for_path and in gio::VfsImpl::get_file_for_path to impl AsRef<std::path::Path> as in gio::File::for_path .
What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix the annotation upstream for VfsExt::file_for_path then

@fbrouille fbrouille force-pushed the gio_file_subclass branch from bbfa6db to ce47c8b Compare March 5, 2025 18:52
@fbrouille
Copy link
Contributor Author

OOC I'm planning to implement some nautilus extension in Rust (very challenging 😅)

}
}

unsafe impl IsImplementable<MyFile> for File {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this into subclass/file.rs even if it only implements a small subset of the vfuncs, the rest can be added later.

@bilelmoussaoui
Copy link
Member

would you mind rebasing & finishing the small remaining bits here?

@fbrouille
Copy link
Contributor Author

Yes, I'm adding subclass/file.rs (with almost all vfuncs), tests and a complete example to show how to implement a custom Vfs. I will share it during next week.

@fbrouille fbrouille changed the title Add gio::FileEnumerator, gio::FileMonitor, gio::Vfs subclasses Add gio::File, gio::FileEnumerator, gio::FileMonitor, gio::Vfs subclasses Apr 26, 2025
@fbrouille fbrouille force-pushed the gio_file_subclass branch 5 times, most recently from c7d3812 to 7e9bab9 Compare April 26, 2025 23:01
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
@fbrouille fbrouille force-pushed the gio_file_subclass branch 2 times, most recently from 47a3003 to e9842cc Compare April 30, 2025 11:01
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>

// Support parent implementation of virtual functions defined in `gio::ffi::GFileMonitorClass`.
pub trait FileMonitorImplExt: FileMonitorImpl {
fn parent_cancel(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return of this vfunc doesn't seem to be used https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gfilemonitor.c#L254, weird but maybe we can make it return Option and fallback to TRUE if the user has no clue what to return (which is expected, i guess?)

Comment on lines +103 to +107
// default implementation provided by GIO
// klass.next_files_async = Some(next_files_async::<T>);
// klass.next_files_finish = Some(next_files_finish::<T>);
// klass.close_async = Some(close_async::<T>);
// klass.close_finish = Some(close_finish::<T>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TODO comment so they can easily be grep-ed for ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at least document the why it is like this

@@ -1111,6 +1113,98 @@ pub trait FileExtManual: IsA<File> + Sized {

(fut, Box::pin(receiver))
}

#[doc(alias = "g_file_set_attribute")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be split and we can land it already

Comment on lines +31 to +32
use gio::{Cancellable, File, FileMonitorFlags};
let _ = File::for_uri("resource:/").monitor_file(FileMonitorFlags::NONE, Cancellable::NONE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you create a GType from the names and then calling T::ensure_type on it?

Comment on lines +19 to +21
glib::wrapper! {
#[doc(alias = "GResourceFileMonitor")]
pub struct ResourceFileMonitor(Object<ffi::GResourceFileMonitor, ffi::GResourceFileMonitorClass>) @extends FileMonitor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceFileMonitor why is this here? i don't feel like it should be part of the test...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants