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 diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index f4e35c5b7f..bab9ba0cea 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 errno == 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));