Merge branch 'wip/oholy/btrfs-copy-fix' into 'main'

gfile: Fix file size detection when copying on btrfs

See merge request GNOME/glib!3309
This commit is contained in:
Philip Withnall 2023-03-06 17:40:45 +00:00
commit 7187243b8e

View File

@ -3158,15 +3158,25 @@ btrfs_reflink_with_progress (GInputStream *in,
gpointer progress_callback_data, gpointer progress_callback_data,
GError **error) GError **error)
{ {
goffset source_size; goffset total_size;
int fd_in, fd_out; int fd_in, fd_out;
int ret, errsv; int ret, errsv;
fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in)); fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out)); fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
total_size = -1;
/* avoid performance impact of querying total size when it's not needed */
if (progress_callback) if (progress_callback)
source_size = g_file_info_get_size (info); {
struct stat sbuf;
if (fstat (fd_in, &sbuf) == 0)
total_size = sbuf.st_size;
}
if (total_size == -1)
total_size = 0;
/* Btrfs clone ioctl properties: /* Btrfs clone ioctl properties:
* - Works at the inode level * - Works at the inode level
@ -3201,7 +3211,7 @@ btrfs_reflink_with_progress (GInputStream *in,
/* Make sure we send full copied size */ /* Make sure we send full copied size */
if (progress_callback) if (progress_callback)
progress_callback (source_size, source_size, progress_callback_data); progress_callback (total_size, total_size, progress_callback_data);
return TRUE; return TRUE;
} }