From f8250894889810f0c9c0e52368ef02b3f5542561 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 5 Feb 2024 11:32:34 +0800 Subject: [PATCH 1/3] fix: file not exist on windows --- source/os/src/osFile.c | 7 +++++++ source/util/src/tlog.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index f4e35c5b7f..d20640cc0e 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -632,6 +632,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in return writeLen; } +bool lastErrorIsFileNotExist() { + DWORD dwError = GetLastError(); + return dwError == ERROR_FILE_NOT_FOUND; +} + #else int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { int access = O_BINARY; @@ -1028,6 +1033,8 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in #endif } +bool lastErrorIsFileNotExist() { return dwError == ENOENT; } + #endif // WINDOWS TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 505ce61eca..eae02125d2 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -350,7 +350,7 @@ void taosResetLog() { static bool taosCheckFileIsOpen(char *logFileName) { TdFilePtr pFile = taosOpenFile(logFileName, TD_FILE_WRITE); if (pFile == NULL) { - if (errno == ENOENT) { + if (lastErrorIsFileNotExist()) { return false; } else { printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); From 9457d3a269dea3d87a1e6384060a24335bb62dbd Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 5 Feb 2024 16:07:40 +0800 Subject: [PATCH 2/3] fix: build failed on linux --- source/os/src/osFile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index d20640cc0e..bab9ba0cea 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -1033,7 +1033,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in #endif } -bool lastErrorIsFileNotExist() { return dwError == ENOENT; } +bool lastErrorIsFileNotExist() { return errno == ENOENT; } #endif // WINDOWS From 7ca37dc4a6841781e334e5877f16f3d748e36e51 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 5 Feb 2024 16:39:24 +0800 Subject: [PATCH 3/3] fix: build error --- include/os/osFile.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/os/osFile.h b/include/os/osFile.h index 4d760a791f..eb0862a719 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -119,6 +119,8 @@ int32_t taosSetFileHandlesLimit(); int32_t taosLinkFile(char *src, char *dst); +bool lastErrorIsFileNotExist(); + #ifdef __cplusplus } #endif