Skip to content

Commit e31db89

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb3e368 commit e31db89

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

reftable/stack.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ static int stack_fsync(const struct reftable_write_options *opts, int fd)
4848
return fsync(fd);
4949
}
5050

51+
static ssize_t reftable_write_data(int fd, const void *data, size_t size)
52+
{
53+
size_t total_written = 0;
54+
const char *p = data;
55+
56+
while (total_written < size) {
57+
ssize_t bytes_written = write(fd, p, size - total_written);
58+
if (bytes_written < 0 && (errno == EAGAIN || errno == EINTR))
59+
continue;
60+
if (bytes_written < 0)
61+
return REFTABLE_IO_ERROR;
62+
63+
total_written += bytes_written;
64+
p += bytes_written;
65+
}
66+
67+
return total_written;
68+
}
69+
5170
struct fd_writer {
5271
const struct reftable_write_options *opts;
5372
int fd;
@@ -56,7 +75,7 @@ struct fd_writer {
5675
static ssize_t fd_writer_write(void *arg, const void *data, size_t sz)
5776
{
5877
struct fd_writer *writer = arg;
59-
return write_in_full(writer->fd, data, sz);
78+
return reftable_write_data(writer->fd, data, sz);
6079
}
6180

6281
static int fd_writer_flush(void *arg)
@@ -784,7 +803,8 @@ int reftable_addition_commit(struct reftable_addition *add)
784803
goto done;
785804
}
786805

787-
err = write_in_full(add->tables_list_lock.fd, table_list.buf, table_list.len);
806+
err = reftable_write_data(add->tables_list_lock.fd,
807+
table_list.buf, table_list.len);
788808
reftable_buf_release(&table_list);
789809
if (err < 0) {
790810
err = REFTABLE_IO_ERROR;
@@ -1470,8 +1490,8 @@ static int stack_compact_range(struct reftable_stack *st,
14701490
goto done;
14711491
}
14721492

1473-
err = write_in_full(tables_list_lock.fd,
1474-
tables_list_buf.buf, tables_list_buf.len);
1493+
err = reftable_write_data(tables_list_lock.fd,
1494+
tables_list_buf.buf, tables_list_buf.len);
14751495
if (err < 0) {
14761496
err = REFTABLE_IO_ERROR;
14771497
unlink(new_table_path.buf);

0 commit comments

Comments
 (0)