After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777187 - g_file_query_exists returns TRUE for files in inaccessible dirs
g_file_query_exists returns TRUE for files in inaccessible dirs
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gio
2.50.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-01-12 18:23 UTC by Jan Alexander Steffens (heftig)
Modified: 2018-05-24 19:22 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jan Alexander Steffens (heftig) 2017-01-12 18:23:42 UTC
.
Comment 1 Jan Alexander Steffens (heftig) 2017-01-12 18:23:51 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):
  • File "<stdin>", line 1 in <module>
GLib.Error: g-io-error-quark: Error when getting information for file '/nonexistent': No such file or directory (1)



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
Comment 2 Emmanuele Bassi (:ebassi) 2017-01-12 18:35:37 UTC
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
Comment 3 Emmanuele Bassi (:ebassi) 2017-01-12 18:38:54 UTC
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
Comment 4 GNOME Infrastructure Team 2018-05-24 19:22:18 UTC
-- 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.