Skip to content

Fix return value for File::for_commandline_arg #145

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gio/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ manual_traits = ["FileExtManual"]
[[object.function.parameter]]
name = "arg"
string_type = "os_string"
[object.function.return]
nullable = true
Comment on lines +549 to +550
Copy link
Member

Choose a reason for hiding this comment

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

This can never be nullable per the docs "This operation never fails, but the returned object might not support any I/O operation if arg points to a malformed path."

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue seems to say otherwise though...

Copy link
Member Author

Choose a reason for hiding this comment

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

And the source code seems to do it too: https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gfile.c#L6728

The doc is lying.

[[object.function]]
name = "new_for_commandline_arg_and_cwd"
# Not annotated as constructor in Gir => force it to apply naming convention
Expand Down
2 changes: 1 addition & 1 deletion gio/src/auto/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl File {

#[doc(alias = "g_file_new_for_commandline_arg")]
#[doc(alias = "new_for_commandline_arg")]
pub fn for_commandline_arg<P: AsRef<std::ffi::OsStr>>(arg: P) -> File {
pub fn for_commandline_arg<P: AsRef<std::ffi::OsStr>>(arg: P) -> Option<File> {
unsafe {
from_glib_full(ffi::g_file_new_for_commandline_arg(
arg.as_ref().to_glib_none().0,
Expand Down