diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 039d688526c4cb1bbcc3ad3163bf3d47437ee625..9202792663fd9802672d06538483aa53bbff4524 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -179,7 +179,7 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co fwrite(buffer, 1, rlen, out_file); return (int64_t)(writeLen + rlen); } else { - fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); + fwrite(buffer, 1, _SEND_FILE_STEP_, out_file); writeLen += _SEND_FILE_STEP_; } } @@ -223,7 +223,7 @@ int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { if (rlen <= 0) { return writeLen; } else { - taosWriteSocket(sfd, buffer, (int32_t)remain); + taosWriteSocket(dfd, buffer, (int32_t)remain); writeLen += remain; } } diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index bb124dec06e49be23f3a1572d8a878a694811977..03923fbc521a69d2db4d8101c7cea4afc28cd444 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -125,7 +125,14 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { ret = fseek(pTSBuf->f, 0, SEEK_END); UNUSED(ret); - + + // file meta data may be cached, close and reopen the file for accurate file size. + fclose(pTSBuf->f); + pTSBuf->f = fopen(pTSBuf->path, "rb+"); + if (pTSBuf->f == NULL) { + return pTSBuf; + } + struct stat fileStat; if (fstat(fileno(pTSBuf->f), &fileStat) != 0) { tsBufDestroy(pTSBuf);