GNOME Bugzilla – Bug 777187
g_file_query_exists returns TRUE for files in inaccessible dirs
Last modified: 2018-05-24 19:22:18 UTC
.
~> python Python 3.6.0 (default, Dec 24 2016, 08:03:08) [GCC 6.2.1 20160830] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import GLib, Gio >>> GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION (2, 50, 1) Querying info for an accessible path works as expected: >>> Gio.File.new_for_path("/").query_info("*", 0).list_attributes() ['standard::type', 'standard::name', 'standard::display-name', 'standard::edit-name', 'standard::copy-name', 'standard::icon', 'standard::content-type', 'standard::fast-content-type', 'standard::size', 'standard::allocated-size', 'standard::symbolic-icon', 'etag::value', 'id::file', 'id::filesystem', 'access::can-read', 'access::can-write', 'access::can-execute', 'access::can-delete', 'access::can-trash', 'access::can-rename', 'time::modified', 'time::modified-usec', 'time::access', 'time::access-usec', 'time::changed', 'time::changed-usec', 'unix::device', 'unix::inode', 'unix::mode', 'unix::nlink', 'unix::uid', 'unix::gid', 'unix::rdev', 'unix::block-size', 'unix::blocks', 'owner::user', 'owner::user-real', 'owner::group'] Querying info for an inaccessible path works, too: >>> Gio.File.new_for_path("/root").query_info("*", 0).list_attributes() ['standard::type', 'standard::name', 'standard::display-name', 'standard::edit-name', 'standard::copy-name', 'standard::icon', 'standard::content-type', 'standard::fast-content-type', 'standard::size', 'standard::allocated-size', 'standard::symbolic-icon', 'etag::value', 'id::file', 'id::filesystem', 'access::can-read', 'access::can-write', 'access::can-execute', 'access::can-delete', 'access::can-trash', 'access::can-rename', 'time::modified', 'time::modified-usec', 'time::access', 'time::access-usec', 'time::changed', 'time::changed-usec', 'unix::device', 'unix::inode', 'unix::mode', 'unix::nlink', 'unix::uid', 'unix::gid', 'unix::rdev', 'unix::block-size', 'unix::blocks', 'owner::user', 'owner::user-real', 'owner::group'] Querying info for a file that Gio knows doesn't exist raises an error, as expected: >>> Gio.File.new_for_path("/nonexistent").query_info("*", 0) Traceback (most recent call last):
+ Trace 237058
Querying info for a file in an inaccessible dir, however, succeeds as well, although only standard::* attributes are returned: >>> Gio.File.new_for_path("/root/nonexistent").query_info("*", 0).list_attributes() ['standard::name', 'standard::display-name', 'standard::edit-name', 'standard::copy-name', 'standard::icon', 'standard::content-type', 'standard::fast-content-type', 'standard::symbolic-icon'] And, as far as g_file_query_exists is concerned, the file exists: >>> Gio.File.new_for_path("/root/nonexistent").query_exists() True
So, I think the issue is that: stat /root/nonexistent returns EACCESS, which is handled specially in GLocalFileInfo: https://git.gnome.org//browse/glib/tree/gio/glocalfileinfo.c#n1755
If you owned the path to a non-existent file, you'd get False: >>> from gi.repository import GLib >>> GLib.get_user_name() 'ebassi' >>> from gi.repository import Gio >>> Gio.File.new_for_path('/home/ebassi/Desktop/nonexistent').query_exists() False
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1237.