Commit Graph

186 Commits

Author SHA1 Message Date
Philip Withnall
46d3a016f3 Merge branch 'write_info_file_fail' into 'main'
GLocalFile: add error handle for trash info file writing

See merge request GNOME/glib!3170
2022-12-29 12:33:55 +00:00
wangrong
95c4312941 GLocalFile: add error handle for trash info file writing 2022-12-29 12:33:55 +00:00
wangrong
333e9fc0ba GLocalFile: Delete redundant error saving statement 2022-12-29 12:29:39 +00:00
Philip Withnall
bcb5eee0ea glocalfile: Support marking fuse.sshfs filesystems as remote
This requires checking the type of a filesystem using `/proc/mounts`
rather than `statfs()`, since `statfs()` doesn’t give the subtype of the
mount. So it only returns `fuse` rather than `fuse.sshfs`.

This commit changes the output of `gio info -f ./path/to/local/sshfs/mount`
from `filesystem::remote: FALSE` to `filesystem::remote: TRUE`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2726
2022-10-17 16:05:58 +01:00
nitinosiris
b33ef610de Add functionality to preserve nanosecond timestamps
file copy doesn't preserve nanosecond timestamps

Closes #369
2022-05-27 17:03:35 +01:00
Philip Withnall
5942cd7984 gio: Add SPDX license headers automatically
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.

This commit was entirely generated using the command:
```
git ls-files gio/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-05-18 09:18:52 +01:00
Egor Bychin
16ce10eb3c glocalfile: Fix g_stat return value not being checked 2021-10-11 13:55:17 +03:00
markus
648994dba4 glocalfile: Fix the global trash dir detection
The `g_file_trash` function fails with the `Unable to find or create trash
directory` error when the global `.Trash` directory exists. This is because
the commit 7f2af262 introduced the `gboolean success` variable to signalize
the detection of the trash folder, but didn't set it in all code branches.
Since for a time this variable was not initialized the bug wasn't visible
when the trash folder existed. The bug became effective after the `success`
variable was initialized with `FALSE` by the commit c983ded0. Let's explicitly
set the `success` variable in all branches to fix the global trash dir
detection.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2439
2021-07-12 11:08:25 +01:00
Leigh Scott
762b284ecc glocalfile: Add native exfat magic number to filesystem list 2021-03-29 18:33:31 +01:00
Timm Bäder
c983ded09f glocalfile: Fix an uninitialized variable
Clang says:

../gio/glocalfile.c:2090:11: warning: variable 'success' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
      if (trashdir == NULL)
          ^~~~~~~~~~~~~~~~
../gio/glocalfile.c:2133:12: note: uninitialized use occurs here
      if (!success)
           ^~~~~~~
../gio/glocalfile.c:2090:7: note: remove the 'if' if its condition is always true
      if (trashdir == NULL)
      ^~~~~~~~~~~~~~~~~~~~~
../gio/glocalfile.c:2041:23: note: initialize the variable 'success' to silence this warning
      gboolean success;
                      ^
                       = 0

So just do that.
2021-01-06 17:36:32 +01:00
Philip Withnall
7f2af262bf glocalfile: Improve wording for error messages about trash directories
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #1283
2021-01-04 14:43:54 +00:00
Philip Withnall
8cec87ff46 glocalfile: Clarify an error message slightly
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-22 18:22:37 +00:00
Philip Withnall
3a7acd24a9 glocalfile: Add an assertion to help static analysis
Static analysis of the call to `g_dir_new_from_dirp()` is tricky,
because the call is across library boundaries and indirected through a
vfunc map because it’s private to libglib.

Help the static analyser by adding an assertion about the input and
output values for `g_dir_new_from_dirp()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-08 11:16:43 +00:00
Philip Withnall
24b5d86d4a glocalfile: Check g_stat() return value
There were a couple of places where the return value wasn’t checked, and
hence failure could not be noticed.

Coverity CIDs: #1159435, #1159426

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-03 15:26:03 +00:00
Simon McVittie
642baa50fa glocalfile: Never require G_LOCAL_FILE_STAT_FIELD_ATIME
Some filesystems don't have meaningful access times under at least some
circumstances (see #2189, #2205). In this situation the traditional stat()
and related kernel interfaces have to put something meaningless in the
st_atime field, and have no way to signal that it is meaningless.

However, statx() does have a way to signal that the atime is meaningless:
if the filesystem doesn't provide a useful access time, it will unset
the STATX_ATIME bit (as well as filling in the same meaningless value
for the stx_atime field that stat() would have used, for compatibility).
We don't actually *need* the atime, so never include it in the required
mask. This was already done for one code path in commit 6fc143bb
"gio: Allow no atime from statx" to fix #2189, but other callers were
left unchanged in that commit, and receive the same change here.

It is not actually guaranteed that *any* of the flags in the
returned stx_mask will be set (the only guarantee is that items in
STATX_BASIC_STATS have at least a harmless compatibility value, even if
their corresponding flag is cleared), so it might be better to follow
this up by removing the concept of the required mask entirely. However,
as of Linux 5.8 it looks as though STATX_ATIME is the only flag in
STATX_BASIC_STATS that might be cleared in practice, so this simpler
change fixes the immediate regression.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2205
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-15 10:09:46 +01:00
Andre Miranda
622806d5cf glocalfileinfo: Add support for optional/required fields in stat bufs
This is a step towards supporting `statx()`, which allows the set of
fields it returns to be specified by the caller. Currently, the existing
`stat()` and `fstat()` calls continue to be made, and there are no
behavioural changes — but the new wrapper functions will be extended in
future.

Helps: #1970
2020-08-14 17:30:11 +01:00
Andre Miranda
8edbfe8bb0 glocalfileinfo: Use accessors to access struct stat members
This will allow the actual struct in use to be changed in future without
code changes everywhere.

Helps: #1970
2020-08-14 17:30:11 +01:00
Ondrej Holy
4602a5ee17 gfile: Add support for x-gvfs-notrash option to ignore mounts
Add support for x-gvfs-notrash mount option, which allows to disable
trash functionality for certain mounts. This might be especially useful
e.g. to prevent trash folder creation on enterprise shares, which are
also accessed from Windows...

https://bugzilla.redhat.com/show_bug.cgi?id=1096200
2020-08-05 13:07:04 +01:00
Philip Withnall
b79747eee1 Merge branch 'remove-broken-xp-code' into 'master'
gio: Remove broken support for XP

See merge request GNOME/glib!1583
2020-07-27 02:07:43 +00:00
Philip Withnall
3b6460b94c glib: Use g_file_set_contents_full() throughout GLib and GIO
Where applicable. Where the current use of `g_file_set_contents()` seems
the most appropriate, leave that in place.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Nirbheek Chauhan
4e485d76ac gio: Remove broken support for XP
We now require Windows 7 or newer, and the networking code hasn't
worked in a long time since we directly use symbols from iphlapi.dll
now.
2020-07-26 21:30:05 +05:30
Philip Withnall
a63efa4291 tree: Fix various ableist language
In almost all cases, rewording the documentation/comments made things
more specific and a little clearer.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1544#note_846645
2020-06-23 10:49:44 +01:00
Ondrej Holy
92c9960521 glocalfile: Add SMB on the list of remote filesystems
The G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE is set to TRUE only for NFS
filesystem types currently. Let's add also SMB filesystem types. This
also changes g_local_file_is_nfs_home function logic to handle only
NFS filesystems.
2020-06-19 11:35:09 +02:00
Ondrej Holy
a8f97cbe8e glocalfile: Rename g_local_file_is_remote
The g_local_file_is_remote function is misleading as it works only for
NFS filesystem types and only for locations in home directorly. Let's
rename it to g_local_file_is_nfs_home to make it obvious.
2020-06-19 11:34:42 +02:00
Ondrej Holy
f489f6c4ee glocalfile: Do not call statfs/statvfs several times
statfs/statvfs is called several times when querying filesystem info.
This is because the G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE attribute is set
over is_remote_fs function, which calls statfs/statvfs again. Let's use
the already known fstype instead of redundant statfs/statvfs calls.
This also changes g_local_file_is_remote implementation to use
g_local_file_query_filesystem_info to obtain fstype, which allows to
remove duplicated code from is_remote_fs function.
2020-06-19 11:34:40 +02:00
Ondrej Holy
706dc6b5aa glocalfile: Fix G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE outside home
The G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE currently works only for locations
in the home directory. Let's make it work also for files outside the home
directory.
2020-06-18 13:12:07 +02:00
Ondrej Holy
d067b5390a glocalfile: Remove redundant private header
There are glocalfile.h and glocalfileprivate.h header files currently.
None of those header files is public, so it doesn't make sense to have
two private headers for glocalfile.c. Let's remove glocalfileprivate.h.
2020-06-18 13:12:06 +02:00
Ondrej Holy
387709338c glocalfile: Handle smb2 filesystem type
`G_FILE_ATTRIBUTE_FILESYSTEM_TYPE` is not set for CIFS mounts with
`vers=2.0` option, or newer. Add `smb2` to the list of known filesystems.
It is also reported by `stat -f`:
https://github.com/coreutils/coreutils/blob/master/src/stat.c
2020-06-18 13:12:06 +02:00
Philip Withnall
7d2bce82e2 glocalfile: Don’t define unsupported copy vfunc
The caller assumes that an unimplemented vfunc means that copying is
unsupported (and falls back to its internal copy implementation), so
there’s no point in implementing the vfunc just to unconditionally
return `G_IO_ERROR_NOT_SUPPORTED`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
1b7ab81c1c glocalfile: Don’t define symlink vfunc if it’s unsupported
Rather than defining a vfunc which only ever returns
`G_IO_ERROR_NOT_SUPPORTED`, just don’t define the vfunc at all. The
caller in `GFile` interprets this as symlinks not being supported — so
we get the same behaviour, but without spending a vfunc call on it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Matthias Clasen
bca4ff7c5e Support the trash portal
When we are in a sandbox, try to trash files via a portal.
It works.
2019-01-31 19:00:19 -05:00
Ondrej Holy
a56b9cc6b2 glocalfile: Use MAXSYMLINKS when following symlinks
Currently, readlink() is used only 12 times when expanding symlinks.
However, kernel uses 40 for this purpose and it is defined as MAXSYMLINKS.
Use that constant if available, or 40. See:
https://github.com/torvalds/linux/include/linux/namei.h.
2018-10-23 08:53:55 +02:00
Ondrej Holy
b6191059b8 glocalfile: Return NULL if symlink expansion fails
find_mountpoint_for() uses current file in case of error, because
get_parent() returns NULL for error, but also if parent doesn't exist.
Return "." from get_parent() if parent doesn't exist in order to
differentiate the error state.
2018-10-23 08:53:55 +02:00
Ondrej Holy
0f5017fb70 glocalfile: Fix access::can-trash if parent is symlink
G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH can be set to a wrong value if
its parent dir is a symlink. This is because the find_mountpoint_for()
function tries to find mountpoint for a filepath and expands symlinks
only in parent dirs. But in this case the path is already parent dir
and needs to be expanded first...

Closes: https://gitlab.gnome.org/GNOME/glib/issues/1522
2018-10-17 12:42:04 +02:00
Philip Withnall
61a348f287 glocalfile: Only ignore FS full information for FUSE and ncpfs
Previously, glocalfile.c would not set file system metadata for
the free/used key for file systems which reported 0 free space. This is
because some file systems don’t set that metadata when you call
statfs(), so we can’t reliably report it. However, some do, and they
can legitimately set f_bavail and f_bfree to 0 if the file system is
full.

In order to avoid that, always set the file system metadata unless the
file system is FUSE or ncpfs.

This is a partial revert of commit 0b9f24c1e1: instead of the changes
made in that commit, I think we should maintain a blacklist of file
systems which are known to not correctly report free space.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/328
2018-08-17 12:41:20 +01:00
Iain Lane
1152d99ded Fix trashing on overlayfs
In order to determine whether to trash a file to the home directory, we
compare its st_dev to our home directory's st_dev field.

This is the wrong thing to do on overlayfs when deleting files, because
st_dev contains the ID of the filesystem providing the file (which can
be the lower or upper filesystem), but directories always return the ID
of the overlayfs. Thus the comparison fails and we are unable to trash
the file.

Fix this by checking st_dev of the parent directory when we are deleting
a file.

Also adjust `test_trash_not_supported` for this - make its st_dev check
look at the parent directory's `st_dev` rather than the temporary file's
own.

Fixes #1027.
2018-08-13 17:41:59 +01:00
Iain Lane
93f3cb7c6d Revert "glocalfile: Check that parent device is the same when trashing"
This reverts commit 15cdcd2e0b.
2018-08-13 17:23:21 +01:00
Philip Withnall
92e059280f glib: Don’t use time(NULL) to get current time
Use either g_get_real_time() or g_date_time_new_now_local(). This means
we don’t need to worry about time_t being 32b in future (the year 2038
problem), and it makes the need for error handling a bit more explicit.
Improve the error handling in several cases.

Based on a patch by Niels De Graef
(https://gitlab.gnome.org/GNOME/glib/merge_requests/142).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1402
2018-07-09 13:28:02 +02:00
Philip Withnall
61da8748fd glocalfile: Fix a minor memory leak
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-29 12:13:32 +01:00
Ondrej Holy
1cbb5dd95f glocalfile: Fix error code when trash not found
G_IO_ERROR_NOT_SUPPORTED is used as parameter for g_set_io_error(),
however, errno is expected instead and thus error code is set to 0,
which is wrong. Let's use ENOTSUP instead.
2018-06-08 14:15:18 +02:00
Ondrej Holy
15cdcd2e0b glocalfile: Check that parent device is the same when trashing
To be honest, I am not sure why, but in some special environments (e.g.
our CI integration) can happen, that file device number is different from
parent device number. Return "Unable to find or create trash directory for
%s" error from g_local_file_trash() in that case and also set
G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH appropriately.
2018-06-08 13:27:13 +02:00
Ondrej Holy
13e751cab4 glocalfile: Update G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH logic
Change G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH logic to be consistent
with recent g_local_file_trash changes, i.e. set this to FALSE for
locations on system-internal mounts.

https://gitlab.gnome.org/GNOME/glib/issues/251
2018-06-08 11:24:23 +02:00
Ondrej Holy
d1eaf72c00 glocalfile: Allow trashing only for locations supported by trash:///
New bugs appears periodically in nautilus/gvfs/glib components that not
all trashed files are shown in trash:///. It used to be problem mostly
for "bind mounts" and btrfs subvolumes only. Currently, it is also
problem for nfs, cifs and other filesystems, which have been recently
added by commmit 0d69462f on the list of system internal filesystems.

This happens because the trash backend doesn't monitor files on system
internal mounts. Such behavior is not against the trash-spec, however,
we should be consistent within GNOME.

This behavior has the nice side-effect that it solves issues with hangs
on network filesystems: https://gitlab.gnome.org/GNOME/glib/issues/605,
because those are currently on the system internal filesystem list.

https://gitlab.gnome.org/GNOME/glib/issues/251
2018-06-08 11:24:20 +02:00
Philip Withnall
da3daf2803 Revert "Merge branch 'wip/oholy/trashing-locations' into 'master'"
This reverts merge request !49
2018-06-07 16:42:57 +00:00
Ondrej Holy
6dfd0a00e7 glocalfile: Update G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH logic
Change G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH logic to be consistent
with recent g_local_file_trash changes, i.e. set this to FALSE for
locations on system-internal mounts.

https://gitlab.gnome.org/GNOME/glib/issues/251
2018-06-05 14:53:15 +02:00
Ondrej Holy
15a47afb0e glocalfile: Allow trashing only for locations supported by trash:///
New bugs appears periodically in nautilus/gvfs/glib components that not
all trashed files are shown in trash:///. It used to be problem mostly
for "bind mounts" and btrfs subvolumes only. Currently, it is also
problem for nfs, cifs and other filesystems, which have been recently
added by commmit 0d69462f on the list of system internal filesystems.

This happens because the trash backend doesn't monitor files on system
internal mounts. Such behavior is not against the trash-spec, however,
we should be consistent within GNOME.

This behavior has the nice side-effect that it solves issues with hangs
on network filesystems: https://gitlab.gnome.org/GNOME/glib/issues/605,
because those are currently on the system internal filesystem list.

https://gitlab.gnome.org/GNOME/glib/issues/251
2018-06-05 14:53:15 +02:00
Georges Basile Stavracas Neto
0f37af7e9b glocalfile: Use g_canonicalize_filename
Drop the local function in favor of the exposed
one.

https://bugzilla.gnome.org/show_bug.cgi?id=111848
2018-04-30 21:54:49 +01:00
Christoph Reiter
97c28f7fe1 ci: fix warnings and enable --werror for the mingw build
Fix various warnings regarding unused variables, duplicated
branches etc by adjusting the ifdeffery and some missing casts.

gnulib triggers -Wduplicated-branches in one of the copied files,
disable as that just makes updating the code harder.

The warning indicating missing features are made none fatal through
pragmas. They still show but don't abort the build.

https://bugzilla.gnome.org/show_bug.cgi?id=793729
2018-04-25 17:23:50 +02:00
Ting-Wei Lan
8e91aaed79 glocalfile: Update the list of Linux filesystem magic numbers
Add filesystem magic numbers found in statfs(2) manual page. Filesystem
magic numbers that are not available from the manual page are copied
from Linux source code.

configfs is found in fs/configfs/mount.c, macro CONFIGFS_MAGIC.
fusectl is found in fs/fuse/control.c, macro FUSE_CTL_SUPER_MAGIC.
rpc_pipefs is found in net/sunrpc/rpc_pipe.c, macro RPCAUTH_GSSMAGIC.

https://bugzilla.gnome.org/show_bug.cgi?id=754634
2017-12-19 18:51:00 +08:00
Philip Withnall
d4f07f21fb glocalfile: Fix leak of FS type on some platforms
fstype is a const char*, and is passed to
g_file_info_set_attribute_string(), which takes a copy of it. There’s no
need to g_strdup() the FS type from various statfs/statvfs buffers
beforehand, given that the buffers are valid for the duration of this
function.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=679347
2017-11-15 13:08:11 +00:00