diff --git a/gvfs-helper.c b/gvfs-helper.c index f3e9ddc18ac757..d3aab115fc7f62 100644 --- a/gvfs-helper.c +++ b/gvfs-helper.c @@ -2028,18 +2028,18 @@ static int my_copy_fd_len_tail(int fd_in, int fd_out, ssize_t nr_bytes_total, { memset(buf_tail, 0, tail_len); + if (my_copy_fd_len(fd_in, fd_out, nr_bytes_total) < 0) + return -1; + if (nr_bytes_total < tail_len) - return my_copy_fd_len(fd_in, fd_out, nr_bytes_total); + return 0; - if (my_copy_fd_len(fd_in, fd_out, (nr_bytes_total - tail_len)) < 0) - return -1; + /* Reset the position to read the tail */ + lseek(fd_in, -tail_len, SEEK_CUR); if (xread(fd_in, (char *)buf_tail, tail_len) != tail_len) return -1; - if (write_in_full(fd_out, buf_tail, tail_len) < 0) - return -1; - return 0; }