mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
streaming_write_entry: propagate streaming errors
When we are streaming an index blob to disk, we store the error from stream_blob_to_fd in the "result" variable, and then immediately overwrite that with the return value of "close". That means we catch errors on close (e.g., problems committing the file to disk), but miss anything which happened before then. We can fix this by using bitwise-OR to accumulate errors in our result variable. While we're here, we can also simplify the error handling with an early return, which makes it easier to see under which circumstances we need to clean up. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7b6257b0d4
commit
d9c31e14d0
14
entry.c
14
entry.c
|
@ -120,16 +120,18 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
|
||||||
const struct checkout *state, int to_tempfile,
|
const struct checkout *state, int to_tempfile,
|
||||||
int *fstat_done, struct stat *statbuf)
|
int *fstat_done, struct stat *statbuf)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = 0;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open_output_fd(path, ce, to_tempfile);
|
fd = open_output_fd(path, ce, to_tempfile);
|
||||||
if (0 <= fd) {
|
if (fd < 0)
|
||||||
result = stream_blob_to_fd(fd, ce->sha1, filter, 1);
|
return -1;
|
||||||
|
|
||||||
|
result |= stream_blob_to_fd(fd, ce->sha1, filter, 1);
|
||||||
*fstat_done = fstat_output(fd, state, statbuf);
|
*fstat_done = fstat_output(fd, state, statbuf);
|
||||||
result = close(fd);
|
result |= close(fd);
|
||||||
}
|
|
||||||
if (result && 0 <= fd)
|
if (result)
|
||||||
unlink(path);
|
unlink(path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,15 @@ test_expect_success 'setup corrupt repo' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'setup repo with missing object' '
|
||||||
|
git init missing &&
|
||||||
|
(
|
||||||
|
cd missing &&
|
||||||
|
test_commit content &&
|
||||||
|
rm -f "$(obj_to_file HEAD:content.t)"
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'streaming a corrupt blob fails' '
|
test_expect_success 'streaming a corrupt blob fails' '
|
||||||
(
|
(
|
||||||
cd bit-error &&
|
cd bit-error &&
|
||||||
|
@ -31,4 +40,20 @@ test_expect_success 'streaming a corrupt blob fails' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'read-tree -u detects bit-errors in blobs' '
|
||||||
|
(
|
||||||
|
cd bit-error &&
|
||||||
|
rm -f content.t &&
|
||||||
|
test_must_fail git read-tree --reset -u HEAD
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'read-tree -u detects missing objects' '
|
||||||
|
(
|
||||||
|
cd missing &&
|
||||||
|
rm -f content.t &&
|
||||||
|
test_must_fail git read-tree --reset -u HEAD
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue