mirror of
https://github.com/flatpak/flatpak.git
synced 2026-06-19 14:03:46 -04:00
utils: Add flatpak_copy_bytes
This copies data from one fd to another.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user