From a49302e45850ded159ffcc65e361f99428d647cf Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 27 Apr 2022 15:44:10 +0800 Subject: [PATCH] fix(query): fixed a query coredump in Windows TS-1312O --- src/os/src/detail/osFile.c | 4 ++-- src/query/src/qTsbuf.c | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 039d688526..9202792663 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 bb124dec06..03923fbc52 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); -- GitLab