reftable/stack: stop using write_in_full()

Similar to the preceding commit, drop our use of `write_in_full()` and
implement a new wrapper `reftable_write_full()` that handles this logic
for us. This is done to reduce our dependency on the Git library.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2025-02-18 10:20:38 +01:00 committed by Junio C Hamano
parent cb3e368b69
commit e31db89558

View File

@ -48,6 +48,25 @@ static int stack_fsync(const struct reftable_write_options *opts, int fd)
return fsync(fd);
}
static ssize_t reftable_write_data(int fd, const void *data, size_t size)
{
size_t total_written = 0;
const char *p = data;
while (total_written < size) {
ssize_t bytes_written = write(fd, p, size - total_written);
if (bytes_written < 0 && (errno == EAGAIN || errno == EINTR))
continue;
if (bytes_written < 0)
return REFTABLE_IO_ERROR;
total_written += bytes_written;
p += bytes_written;
}
return total_written;
}
struct fd_writer {
const struct reftable_write_options *opts;
int fd;
@ -56,7 +75,7 @@ struct fd_writer {
static ssize_t fd_writer_write(void *arg, const void *data, size_t sz)
{
struct fd_writer *writer = arg;
return write_in_full(writer->fd, data, sz);
return reftable_write_data(writer->fd, data, sz);
}
static int fd_writer_flush(void *arg)
@ -784,7 +803,8 @@ int reftable_addition_commit(struct reftable_addition *add)
goto done;
}
err = write_in_full(add->tables_list_lock.fd, table_list.buf, table_list.len);
err = reftable_write_data(add->tables_list_lock.fd,
table_list.buf, table_list.len);
reftable_buf_release(&table_list);
if (err < 0) {
err = REFTABLE_IO_ERROR;
@ -1470,8 +1490,8 @@ static int stack_compact_range(struct reftable_stack *st,
goto done;
}
err = write_in_full(tables_list_lock.fd,
tables_list_buf.buf, tables_list_buf.len);
err = reftable_write_data(tables_list_lock.fd,
tables_list_buf.buf, tables_list_buf.len);
if (err < 0) {
err = REFTABLE_IO_ERROR;
unlink(new_table_path.buf);