mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-27 12:00:14 +00:00
filebuf: handle write error in lock_file
When writing to a file with locking not check if writing the locked file actually succeeds. Fix the issue by returning error code and message when writing fails.
This commit is contained in:
parent
f17ed63759
commit
18c4ae70d1
@ -70,6 +70,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
|
||||
git_file source;
|
||||
char buffer[FILEIO_BUFSIZE];
|
||||
ssize_t read_bytes;
|
||||
int error;
|
||||
|
||||
source = p_open(file->path_original, O_RDONLY);
|
||||
if (source < 0) {
|
||||
@ -80,7 +81,8 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
|
||||
}
|
||||
|
||||
while ((read_bytes = p_read(source, buffer, sizeof(buffer))) > 0) {
|
||||
p_write(file->fd, buffer, read_bytes);
|
||||
if ((error = p_write(file->fd, buffer, read_bytes)) < 0)
|
||||
break;
|
||||
if (file->compute_digest)
|
||||
git_hash_update(&file->digest, buffer, read_bytes);
|
||||
}
|
||||
@ -90,6 +92,9 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
|
||||
if (read_bytes < 0) {
|
||||
giterr_set(GITERR_OS, "Failed to read file '%s'", file->path_original);
|
||||
return -1;
|
||||
} else if (error < 0) {
|
||||
giterr_set(GITERR_OS, "Failed to write file '%s'", file->path_lock);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user