utils: Add flatpak_copy_bytes

This copies data from one fd to another.
This commit is contained in:
Alexander Larsson
2017-02-07 16:24:04 +01:00
parent b585e4008e
commit 02202b9e76
2 changed files with 42 additions and 0 deletions

View File

@@ -1984,6 +1984,44 @@ flatpak_openat_noatime (int dfd,
}
}
#define COPY_BUFFER_SIZE (16*1024)
gboolean
flatpak_copy_bytes (int fdf,
int fdt,
GError **error)
{
char buf[COPY_BUFFER_SIZE];
int r;
g_return_val_if_fail (fdf >= 0, FALSE);
g_return_val_if_fail (fdt >= 0, FALSE);
for (;;)
{
size_t m = COPY_BUFFER_SIZE;
ssize_t n;
n = read (fdf, buf, m);
if (n < 0)
{
glnx_set_error_from_errno (error);
return FALSE;
}
if (n == 0) /* EOF */
break;
r = glnx_loop_write (fdt, buf, (size_t) n);
if (r < 0)
{
errno = r;
glnx_set_error_from_errno (error);
return FALSE;
}
}
return TRUE;
}
gboolean
flatpak_cp_a (GFile *src,
GFile *dest,

View File

@@ -362,6 +362,10 @@ gboolean flatpak_openat_noatime (int dfd,
GCancellable *cancellable,
GError **error);
gboolean flatpak_copy_bytes (int fdf,
int fdt,
GError **error);
typedef enum {
FLATPAK_CP_FLAGS_NONE = 0,
FLATPAK_CP_FLAGS_MERGE = 1<<0,