diff --git a/include/os/osDir.h b/include/os/osDir.h index eda83ea0ea..223c603352 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -21,7 +21,7 @@ extern "C" { #endif void taosRemoveDir(const char *dirname); -int32_t taosDirExist(char *dirname); +bool taosDirExist(char *dirname); int32_t taosMkDir(const char *dirname); void taosRemoveOldFiles(const char *dirname, int32_t keepDays); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); diff --git a/include/os/osFile.h b/include/os/osFile.h index cbd5d693c5..7e3a5277c8 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -25,8 +25,12 @@ extern "C" { #ifndef ALLOW_FORBID_FUNC #define open OPEN_FUNC_TAOS_FORBID #define fopen FOPEN_FUNC_TAOS_FORBID - // #define close CLOSE_FUNC_TAOS_FORBID - // #define fclose FCLOSE_FUNC_TAOS_FORBID + #define access ACCESS_FUNC_TAOS_FORBID + #define stat STAT_FUNC_TAOS_FORBID + #define lstat LSTAT_FUNC_TAOS_FORBID + #define fstat FSTAT_FUNC_TAOS_FORBID + #define close CLOSE_FUNC_TAOS_FORBID + #define fclose FCLOSE_FUNC_TAOS_FORBID #endif #ifndef PATH_MAX @@ -44,6 +48,12 @@ typedef struct TdFile *TdFilePtr; #define TD_FILE_AUTO_DEL 0x0040 #define TD_FILE_EXCL 0x0080 #define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosGetLineFile, taosEOFFile +TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions); + +#define TD_FILE_ACCESS_EXIST_OK 0x1 +#define TD_FILE_ACCESS_READ_OK 0x2 +#define TD_FILE_ACCESS_WRITE_OK 0x4 +bool taosCheckAccessFile(const char *pathname, int mode); int32_t taosLockFile(TdFilePtr pFile); int32_t taosUnLockFile(TdFilePtr pFile); @@ -51,9 +61,9 @@ int32_t taosUnLockFile(TdFilePtr pFile); int32_t taosUmaskFile(int32_t maskVal); int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime); +int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno); int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime); - -TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions); +bool taosCheckExistFile(const char *pathname); int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence); int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length); @@ -62,7 +72,7 @@ int32_t taosFsyncFile(TdFilePtr pFile); int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset); int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); -void taosFprintfFile(TdFilePtr pFile, const char *format, ...); +void taosFprintfFile(TdFilePtr pFile, const char *format, ...); int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); int32_t taosEOFFile(TdFilePtr pFile); @@ -71,7 +81,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile); int32_t taosRenameFile(const char *oldName, const char *newName); int64_t taosCopyFile(const char *from, const char *to); -void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath); +void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath); int64_t taosSendFile(SocketFd fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size); int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size); @@ -79,7 +89,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length); bool taosValidFile(TdFilePtr pFile); -int taosGetErrorFile(TdFilePtr pFile); +int32_t taosGetErrorFile(TdFilePtr pFile); #ifdef __cplusplus } diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index 4821d60875..563efe4d54 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -1,6 +1,4 @@ -#include "tcommon.h" #include -#include #include #pragma GCC diagnostic push @@ -10,6 +8,8 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" +#include "tep.h" +#include "tcommon.h" #include "taos.h" #include "tvariant.h" #include "tdef.h" diff --git a/source/common/test/tmsgTest.cpp b/source/common/test/tmsgTest.cpp index ca33d24a8c..e8c3284ea5 100644 --- a/source/common/test/tmsgTest.cpp +++ b/source/common/test/tmsgTest.cpp @@ -1,6 +1,6 @@ #include -#include "gtest/gtest.h" +#include #include "tmsg.h" diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index 6d5085ee74..ce00c98ff9 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -90,7 +90,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F char name[pathLen + 10]; strcpy(name, path); - if (taosDirExist(name) != 0 && taosMkDir(name) != 0) { + if (!taosDirExist(name) && taosMkDir(name) != 0) { terrno = TSDB_CODE_TQ_FAILED_TO_CREATE_DIR; tqError("failed to create dir:%s since %s ", name, terrstr()); } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 2e7116969e..7a95820115 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -580,7 +580,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid SDFile *pRSmadF = TSDB_READ_SMAD_FILE(&(pCommith->readh)); SDFile *pWSmadF = TSDB_COMMIT_SMAD_FILE(pCommith); - if (access(TSDB_FILE_FULL_NAME(pRSmadF), F_OK) != 0) { + if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmadF))) { tsdbDebug("vgId:%d create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmadF)); tsdbInitDFile(pRepo, pWSmadF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAD); @@ -614,7 +614,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid SDFile *pRSmalF = TSDB_READ_SMAL_FILE(&(pCommith->readh)); SDFile *pWSmalF = TSDB_COMMIT_SMAL_FILE(pCommith); - if ((pCommith->isLFileSame) && access(TSDB_FILE_FULL_NAME(pRSmalF), F_OK) == 0) { + if ((pCommith->isLFileSame) && taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmalF))) { tsdbInitDFileEx(pWSmalF, pRSmalF); if (tsdbOpenDFile(pWSmalF, O_RDWR) < 0) { tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF), diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index dcc9700d83..411a166caa 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -314,7 +314,7 @@ int tsdbOpenFS(STsdb *pRepo) { tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current); tsdbGetRtnSnap(pRepo, &pRepo->rtn); - if (access(current, F_OK) == 0) { + if (taosCheckExistFile(current)) { if (tsdbOpenFSFromCurrent(pRepo) < 0) { tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno)); return -1; diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 4d70c429ff..74fb8c1c1f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -443,25 +443,24 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) { } static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) { - struct stat dfstat; SDFile df; tsdbInitDFileEx(&df, pDFile); - if (access(TSDB_FILE_FULL_NAME(pDFile), F_OK) != 0) { + if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pDFile))) { tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile)); // pRepo->state |= TSDB_STATE_BAD_DATA; TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); return 0; } - - if (stat(TSDB_FILE_FULL_NAME(&df), &dfstat) < 0) { + int64_t file_size = 0; + if (taosStatFile(TSDB_FILE_FULL_NAME(&df), &file_size, NULL) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - if (pDFile->info.size < dfstat.st_size) { + if (pDFile->info.size < file_size) { // if (tsdbOpenDFile(&df, O_WRONLY) < 0) { if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) { return -1; @@ -480,10 +479,10 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) { tsdbCloseDFile(&df); tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), - dfstat.st_size, pDFile->info.size); - } else if (pDFile->info.size > dfstat.st_size) { + file_size, pDFile->info.size); + } else if (pDFile->info.size > file_size) { tsdbError("vgId:%d data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it", - REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), dfstat.st_size, pDFile->info.size); + REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), file_size, pDFile->info.size); // pRepo->state |= TSDB_STATE_BAD_DATA; TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); terrno = TSDB_CODE_TDB_FILE_CORRUPTED; diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index 78625d1eed..d766f3cbf1 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -1,4 +1,3 @@ -add_definitions("-D ALLOW_FORBID_FUNC") add_subdirectory(transport) add_subdirectory(sync) add_subdirectory(tdb) diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index b417a645be..b05fc7812a 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -14,9 +14,7 @@ */ #include -#include #include -#include "os.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -24,8 +22,10 @@ #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wformat" +#include -#include "addr_any.h" +#include "os.h" +#include "tglobal.h" #include "catalog.h" #include "stub.h" #include "taos.h" diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index c400ded1c1..d449d7fac4 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -2215,10 +2215,10 @@ static void destroyTsComp(STaskRuntimeEnv *pRuntimeEnv, STaskAttr *pQueryAttr) { if (pQueryAttr->tsCompQuery && pRuntimeEnv->outputBuf && pRuntimeEnv->outputBuf->pDataBlock && taosArrayGetSize(pRuntimeEnv->outputBuf->pDataBlock) > 0) { SColumnInfoData* pColInfoData = taosArrayGet(pRuntimeEnv->outputBuf->pDataBlock, 0); if (pColInfoData) { - FILE *f = *(FILE **)pColInfoData->pData; // TODO refactor - if (f) { - fclose(f); - *(FILE **)pColInfoData->pData = NULL; + TdFilePtr pFile = *(TdFilePtr *)pColInfoData->pData; // TODO refactor + if (pFile != NULL) { + taosCloseFile(&pFile); + *(TdFilePtr *)pColInfoData->pData = NULL; } } } diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index 262232ceb1..7d3665a8cc 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -13,10 +13,7 @@ * along with this program. If not, see . */ -#include -#include #include -#include #include #pragma GCC diagnostic push @@ -26,6 +23,9 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" +#include "tglobal.h" +#include "executorimpl.h" +#include "function.h" #include "taos.h" #include "tdef.h" #include "tvariant.h" diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index fc366e4cc8..612b0705ea 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#include #include #include #include @@ -26,6 +25,7 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" +#include "executorimpl.h" #include "executor.h" #include "stub.h" #include "taos.h" diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 16d9893778..8cb2ff9246 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -63,9 +63,9 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off } static int writeCtxGetSize(WriterCtx* ctx) { if (ctx->type == TFile) { - struct stat fstat; - stat(ctx->file.buf, &fstat); - return fstat.st_size; + int64_t file_size = 0; + taosStatFile(ctx->file.buf, &file_size, NULL); + return (int)file_size; } return 0; } @@ -99,9 +99,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int // ctx->file.pFile = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); ctx->file.pFile = taosOpenFile(path, TD_FILE_READ); - struct stat fstat; - stat(path, &fstat); - ctx->file.size = fstat.st_size; + int64_t file_size = 0; + taosFStatFile(ctx->file.pFile, &file_size, NULL); + ctx->file.size = (int)file_size; #ifdef USE_MMAP ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.pFile, ctx->file.size); #endif @@ -142,8 +142,10 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { #endif } if (ctx->file.readOnly == false) { - struct stat fstat; - stat(ctx->file.buf, &fstat); + int64_t file_size = 0; + taosStatFile(ctx->file.buf, &file_size, NULL); + // struct stat fstat; + // stat(ctx->file.buf, &fstat); // indexError("write file size: %d", (int)(fstat.st_size)); } if (remove) { unlink(ctx->file.buf); } diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 457d586ea4..e626fc68ae 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -13,19 +13,17 @@ * along with this program. If not, see . */ -#include "mockCatalog.h" - #include - #include "stub.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat" -#include "addr_any.h" +#include #pragma GCC diagnostic pop +#include "mockCatalog.h" namespace { void generateTestT1(MockCatalogService* mcs) { diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index b971760132..b80efe09ed 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -13,10 +13,8 @@ * along with this program. If not, see . */ -#include #include #include -#include "tglobal.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -25,6 +23,8 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" +#include "function.h" +#include "tglobal.h" #include "astGenerator.h" #include "parserInt.h" #include "taos.h" diff --git a/source/libs/parser/test/plannerTest.cpp b/source/libs/parser/test/plannerTest.cpp index 43daff9fec..095e2f4f97 100644 --- a/source/libs/parser/test/plannerTest.cpp +++ b/source/libs/parser/test/plannerTest.cpp @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#include #include #include #include @@ -25,6 +24,7 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" +#include "function.h" #include "astGenerator.h" #include "parserInt.h" #include "taos.h" diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp index 8ad5a76388..94d4260696 100644 --- a/source/libs/qworker/test/qworkerTests.cpp +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #pragma GCC diagnostic push @@ -26,9 +25,11 @@ #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wpointer-arith" +#include #include "os.h" +#include "tglobal.h" #include "taos.h" #include "tdef.h" #include "tvariant.h" @@ -37,7 +38,6 @@ #include "planner.h" #include "qworker.h" #include "stub.h" -#include "addr_any.h" #include "executor.h" #include "dataSinkMgt.h" diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index fafc1ea42e..13829618a2 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #pragma GCC diagnostic push @@ -26,15 +25,16 @@ #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wpointer-arith" +#include #include "os.h" +#include "tglobal.h" #include "taos.h" #include "tdef.h" #include "tvariant.h" #include "tep.h" #include "stub.h" -#include "addr_any.h" #include "scalar.h" #include "nodes.h" #include "tlog.h" diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index b9aef99088..8eef1836a5 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #pragma GCC diagnostic push @@ -26,15 +25,16 @@ #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wpointer-arith" +#include #include "os.h" +#include "tglobal.h" #include "taos.h" #include "tdef.h" #include "tvariant.h" #include "tep.h" #include "stub.h" -#include "addr_any.h" #include "scalar.h" #include "nodes.h" #include "tlog.h" diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index 11ed3335e6..1a34c20ba0 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -14,19 +14,8 @@ */ #include -#include #include -#include "os.h" - -#include "taos.h" -#include "tdef.h" -#include "tvariant.h" -#include "catalog.h" -#include "scheduler.h" -#include "tep.h" -#include "trpc.h" - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wunused-function" @@ -34,10 +23,21 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wreturn-type" #pragma GCC diagnostic ignored "-Wformat" +#include + +#include "os.h" + +#include "tglobal.h" +#include "taos.h" +#include "tdef.h" +#include "tvariant.h" +#include "catalog.h" +#include "scheduler.h" +#include "tep.h" +#include "trpc.h" #include "schedulerInt.h" #include "stub.h" -#include "addr_any.h" #include "tref.h" namespace { diff --git a/source/libs/sync/test/syncIOSendMsgClientTest.cpp b/source/libs/sync/test/syncIOSendMsgClientTest.cpp index 9e8c7c8b65..0d06c4f811 100644 --- a/source/libs/sync/test/syncIOSendMsgClientTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgClientTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/test/syncIOSendMsgServerTest.cpp b/source/libs/sync/test/syncIOSendMsgServerTest.cpp index 8af9344ed6..1582e097d3 100644 --- a/source/libs/sync/test/syncIOSendMsgServerTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgServerTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp index a297981ee5..9b2cfcf1d8 100644 --- a/source/libs/sync/test/syncIOSendMsgTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/test/syncIOTickPingTest.cpp b/source/libs/sync/test/syncIOTickPingTest.cpp index 1559b57585..42b9a73432 100644 --- a/source/libs/sync/test/syncIOTickPingTest.cpp +++ b/source/libs/sync/test/syncIOTickPingTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/test/syncIOTickQTest.cpp b/source/libs/sync/test/syncIOTickQTest.cpp index 90304079e3..3d31c596bf 100644 --- a/source/libs/sync/test/syncIOTickQTest.cpp +++ b/source/libs/sync/test/syncIOTickQTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/test/syncRaftStoreTest.cpp b/source/libs/sync/test/syncRaftStoreTest.cpp index e533b89a92..9cfbe5a4ea 100644 --- a/source/libs/sync/test/syncRaftStoreTest.cpp +++ b/source/libs/sync/test/syncRaftStoreTest.cpp @@ -1,6 +1,6 @@ -#include "syncRaftStore.h" #include -#include "gtest/gtest.h" +#include +#include "syncRaftStore.h" #include "syncIO.h" #include "syncInt.h" diff --git a/source/libs/sync/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp index 0b397ef921..c1c5658aba 100644 --- a/source/libs/sync/test/syncTest.cpp +++ b/source/libs/sync/test/syncTest.cpp @@ -1,5 +1,5 @@ #include -#include "gtest/gtest.h" +#include #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index cc3b7fa6b9..65d4cf80cc 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -90,7 +90,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) { // get page file from the env, if not opened yet, open it pPgFile = NULL; snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname); - fileExist = (tdbCheckFileAccess(fname, TDB_F_OK) == 0); + fileExist = taosCheckExistFile(fname); if (fileExist) { tdbGnrtFileID(dbfname, fileid, false); pPgFile = tdbEnvGetPageFile(pEnv, fileid); diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index fa9a3297da..fe0f3befd6 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -16,16 +16,16 @@ #include "tdbInt.h" int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { - struct stat statbuf; + int64_t stDev = 0, stIno = 0; - if (stat(fname, &statbuf) < 0) { + if (taosDevInoFile(fname, &stDev, &stIno) < 0) { return -1; } memset(fileid, 0, TDB_FILE_ID_LEN); - ((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; - ((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; + ((uint64_t *)fileid)[0] = stDev; + ((uint64_t *)fileid)[1] = stIno; if (unique) { ((uint64_t *)fileid)[2] = rand(); } @@ -33,35 +33,34 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { return 0; } -int tdbCheckFileAccess(const char *pathname, int mode) { - int flags = 0; +// int tdbCheckFileAccess(const char *pathname, int mode) { +// int flags = 0; - if (mode & TDB_F_OK) { - flags |= F_OK; - } +// if (mode & TDB_F_OK) { +// flags |= F_OK; +// } - if (mode & TDB_R_OK) { - flags |= R_OK; - } +// if (mode & TDB_R_OK) { +// flags |= R_OK; +// } - if (mode & TDB_W_OK) { - flags |= W_OK; - } +// if (mode & TDB_W_OK) { +// flags |= W_OK; +// } - return access(pathname, flags); -} +// return access(pathname, flags); +// } int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize) { - struct stat st; int ret; - - ret = stat(fname, &st); + int64_t file_size = 0; + ret = taosStatFile(fname, &file_size, NULL); if (ret != 0) { return -1; } - ASSERT(st.st_size % pgSize == 0); + ASSERT(file_size % pgSize == 0); - *pSize = st.st_size / pgSize; + *pSize = file_size / pgSize; return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 8108e5aba6..ca05790f77 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -30,10 +30,10 @@ extern "C" { int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); -#define TDB_F_OK 0x1 -#define TDB_R_OK 0x2 -#define TDB_W_OK 0x4 -int tdbCheckFileAccess(const char *pathname, int mode); +// #define TDB_F_OK 0x1 +// #define TDB_R_OK 0x2 +// #define TDB_W_OK 0x4 +// int tdbCheckFileAccess(const char *pathname, int mode); int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize); diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 5ab0b4c0f1..ad550c7804 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -1,4 +1,4 @@ -#include "gtest/gtest.h" +#include #include "tdb.h" diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 944e67c863..26fa90bdef 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -389,7 +389,6 @@ static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg) { static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) { char dirName[TSDB_FILENAME_LEN] = "\0"; - struct stat pstat; if (pCfg->level < 0 || pCfg->level >= TFS_MAX_TIERS) { fError("failed to mount %s to FS since invalid level %d", pCfg->dir, pCfg->level); @@ -422,19 +421,13 @@ static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) { return -1; } - if (access(dirName, W_OK | R_OK | F_OK) != 0) { + if (!taosCheckAccessFile(dirName, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { fError("failed to mount %s to FS since no R/W access rights", pCfg->dir); terrno = TSDB_CODE_FS_INVLD_CFG; return -1; } - if (stat(dirName, &pstat) < 0) { - fError("failed to mount %s to FS since %s", pCfg->dir, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - if (!S_ISDIR(pstat.st_mode)) { + if (!taosIsDir(dirName)) { fError("failed to mount %s to FS since not a directory", pCfg->dir); terrno = TSDB_CODE_FS_INVLD_CFG; return -1; diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index af66304f84..9cb914a670 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -119,29 +119,29 @@ TEST_F(TfsTest, 03_Dir) { char p1[] = "p1"; char ap1[128] = {0}; snprintf(ap1, 128, "%s%s%s", root, TD_DIRSEP, p1); - EXPECT_NE(taosDirExist(ap1), 0); + EXPECT_NE(taosDirExist(ap1), 1); EXPECT_EQ(tfsMkdir(pTfs, p1), 0); - EXPECT_EQ(taosDirExist(ap1), 0); + EXPECT_EQ(taosDirExist(ap1), 1); char p2[] = "p2"; char ap2[128] = {0}; snprintf(ap2, 128, "%s%s%s", root, TD_DIRSEP, p2); SDiskID did = {0}; - EXPECT_NE(taosDirExist(ap2), 0); + EXPECT_NE(taosDirExist(ap2), 1); EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0); - EXPECT_EQ(taosDirExist(ap2), 0); + EXPECT_EQ(taosDirExist(ap2), 1); char p3[] = "p3/p2/p1/p0"; char ap3[128] = {0}; snprintf(ap3, 128, "%s%s%s", root, TD_DIRSEP, p3); - EXPECT_NE(taosDirExist(ap3), 0); + EXPECT_NE(taosDirExist(ap3), 1); EXPECT_NE(tfsMkdir(pTfs, p3), 0); EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0); EXPECT_EQ(tfsMkdirRecurAt(pTfs, p3, did), 0); - EXPECT_EQ(taosDirExist(ap3), 0); + EXPECT_EQ(taosDirExist(ap3), 1); EXPECT_EQ(tfsRmdir(pTfs, p3), 0); - EXPECT_NE(taosDirExist(ap3), 0); + EXPECT_NE(taosDirExist(ap3), 1); char p45[] = "p5"; char p44[] = "p4"; @@ -149,12 +149,12 @@ TEST_F(TfsTest, 03_Dir) { char ap4[128] = {0}; snprintf(ap4, 128, "%s%s%s", root, TD_DIRSEP, p4); - EXPECT_NE(taosDirExist(ap4), 0); + EXPECT_NE(taosDirExist(ap4), 1); EXPECT_EQ(tfsMkdirRecurAt(pTfs, p4, did), 0); - EXPECT_EQ(taosDirExist(ap4), 0); + EXPECT_EQ(taosDirExist(ap4), 1); EXPECT_EQ(tfsRename(pTfs, p44, p45), 0); EXPECT_EQ(tfsRmdir(pTfs, p4), 0); - EXPECT_NE(taosDirExist(ap4), 0); + EXPECT_NE(taosDirExist(ap4), 1); tfsClose(pTfs); } @@ -251,9 +251,9 @@ TEST_F(TfsTest, 04_File) { char af2[128] = {0}; snprintf(af2, 128, "%s%s%s", root, TD_DIRSEP, n2); - EXPECT_EQ(taosDirExist(af2), 0); + EXPECT_EQ(taosDirExist(af2), 1); tfsRemoveFile(&f2); - EXPECT_NE(taosDirExist(af2), 0); + EXPECT_NE(taosDirExist(af2), 1); { STfsDir *pDir = tfsOpendir(pTfs, "t3"); @@ -529,35 +529,35 @@ TEST_F(TfsTest, 05_MultiDisk) { snprintf(ap22, 128, "%s%s%s", root22, TD_DIRSEP, p1); char ap23[128] = {0}; snprintf(ap23, 128, "%s%s%s", root23, TD_DIRSEP, p1); - EXPECT_NE(taosDirExist(ap00), 0); - EXPECT_NE(taosDirExist(ap01), 0); - EXPECT_NE(taosDirExist(ap10), 0); - EXPECT_NE(taosDirExist(ap11), 0); - EXPECT_NE(taosDirExist(ap12), 0); - EXPECT_NE(taosDirExist(ap20), 0); - EXPECT_NE(taosDirExist(ap21), 0); - EXPECT_NE(taosDirExist(ap22), 0); - EXPECT_NE(taosDirExist(ap23), 0); + EXPECT_NE(taosDirExist(ap00), 1); + EXPECT_NE(taosDirExist(ap01), 1); + EXPECT_NE(taosDirExist(ap10), 1); + EXPECT_NE(taosDirExist(ap11), 1); + EXPECT_NE(taosDirExist(ap12), 1); + EXPECT_NE(taosDirExist(ap20), 1); + EXPECT_NE(taosDirExist(ap21), 1); + EXPECT_NE(taosDirExist(ap22), 1); + EXPECT_NE(taosDirExist(ap23), 1); EXPECT_EQ(tfsMkdir(pTfs, p1), 0); - EXPECT_EQ(taosDirExist(ap00), 0); - EXPECT_EQ(taosDirExist(ap01), 0); - EXPECT_EQ(taosDirExist(ap10), 0); - EXPECT_EQ(taosDirExist(ap11), 0); - EXPECT_EQ(taosDirExist(ap12), 0); - EXPECT_EQ(taosDirExist(ap20), 0); - EXPECT_EQ(taosDirExist(ap21), 0); - EXPECT_EQ(taosDirExist(ap22), 0); - EXPECT_EQ(taosDirExist(ap23), 0); + EXPECT_EQ(taosDirExist(ap00), 1); + EXPECT_EQ(taosDirExist(ap01), 1); + EXPECT_EQ(taosDirExist(ap10), 1); + EXPECT_EQ(taosDirExist(ap11), 1); + EXPECT_EQ(taosDirExist(ap12), 1); + EXPECT_EQ(taosDirExist(ap20), 1); + EXPECT_EQ(taosDirExist(ap21), 1); + EXPECT_EQ(taosDirExist(ap22), 1); + EXPECT_EQ(taosDirExist(ap23), 1); EXPECT_EQ(tfsRmdir(pTfs, p1), 0); - EXPECT_NE(taosDirExist(ap00), 0); - EXPECT_NE(taosDirExist(ap01), 0); - EXPECT_NE(taosDirExist(ap10), 0); - EXPECT_NE(taosDirExist(ap11), 0); - EXPECT_NE(taosDirExist(ap12), 0); - EXPECT_NE(taosDirExist(ap20), 0); - EXPECT_NE(taosDirExist(ap21), 0); - EXPECT_NE(taosDirExist(ap22), 0); - EXPECT_NE(taosDirExist(ap23), 0); + EXPECT_NE(taosDirExist(ap00), 1); + EXPECT_NE(taosDirExist(ap01), 1); + EXPECT_NE(taosDirExist(ap10), 1); + EXPECT_NE(taosDirExist(ap11), 1); + EXPECT_NE(taosDirExist(ap12), 1); + EXPECT_NE(taosDirExist(ap20), 1); + EXPECT_NE(taosDirExist(ap21), 1); + EXPECT_NE(taosDirExist(ap22), 1); + EXPECT_NE(taosDirExist(ap23), 1); char p2[] = "p2"; char _ap21[128] = {0}; @@ -565,22 +565,22 @@ TEST_F(TfsTest, 05_MultiDisk) { SDiskID did = {0}; did.level = 2; did.id = 1; - EXPECT_NE(taosDirExist(_ap21), 0); + EXPECT_NE(taosDirExist(_ap21), 1); EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0); - EXPECT_EQ(taosDirExist(_ap21), 0); + EXPECT_EQ(taosDirExist(_ap21), 1); char p3[] = "p3/p2/p1/p0"; char _ap12[128] = {0}; snprintf(_ap12, 128, "%s%s%s", root12, TD_DIRSEP, p3); did.level = 1; did.id = 2; - EXPECT_NE(taosDirExist(_ap12), 0); + EXPECT_NE(taosDirExist(_ap12), 1); EXPECT_NE(tfsMkdir(pTfs, p3), 0); EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0); EXPECT_EQ(tfsMkdirRecurAt(pTfs, p3, did), 0); - EXPECT_EQ(taosDirExist(_ap12), 0); + EXPECT_EQ(taosDirExist(_ap12), 1); EXPECT_EQ(tfsRmdir(pTfs, p3), 0); - EXPECT_NE(taosDirExist(_ap12), 0); + EXPECT_NE(taosDirExist(_ap12), 1); char p45[] = "p5"; char p44[] = "p4"; @@ -590,12 +590,12 @@ TEST_F(TfsTest, 05_MultiDisk) { did.level = 2; did.id = 2; - EXPECT_NE(taosDirExist(_ap22), 0); + EXPECT_NE(taosDirExist(_ap22), 1); EXPECT_EQ(tfsMkdirRecurAt(pTfs, p4, did), 0); - EXPECT_EQ(taosDirExist(_ap22), 0); + EXPECT_EQ(taosDirExist(_ap22), 1); EXPECT_EQ(tfsRename(pTfs, p44, p45), 0); EXPECT_EQ(tfsRmdir(pTfs, p4), 0); - EXPECT_NE(taosDirExist(_ap22), 0); + EXPECT_NE(taosDirExist(_ap22), 1); } //------------- File -----------------// @@ -660,7 +660,7 @@ TEST_F(TfsTest, 05_MultiDisk) { char af2[128] = {0}; snprintf(af2, 128, "%s%s%s", root23, TD_DIRSEP, n2); - EXPECT_EQ(taosDirExist(af2), 0); + EXPECT_EQ(taosDirExist(af2), 1); tfsRemoveFile(&f2); { @@ -678,7 +678,7 @@ TEST_F(TfsTest, 05_MultiDisk) { tfsClosedir(pDir); } - EXPECT_NE(taosDirExist(af2), 0); + EXPECT_NE(taosDirExist(af2), 1); EXPECT_GT(tfsCopyFile(&f1, &f2), 0); { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index ae0b0bd849..e64260c541 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -64,10 +64,10 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - struct stat statbuf; - stat(fnameStr, &statbuf); - int readSize = TMIN(WAL_MAX_SIZE + 2, statbuf.st_size); - pLastFileInfo->fileSize = statbuf.st_size; + int64_t file_size = 0; + taosStatFile(fnameStr, &file_size, NULL); + int readSize = TMIN(WAL_MAX_SIZE + 2, file_size); + pLastFileInfo->fileSize = file_size; TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pFile == NULL) { @@ -177,11 +177,11 @@ int walCheckAndRepairMeta(SWal* pWal) { SWalFileInfo *pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz-1); char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - struct stat statbuf; - stat(fnameStr, &statbuf); + int64_t file_size = 0; + taosStatFile(fnameStr, &file_size, NULL); - if (oldSz != newSz || pLastFileInfo->fileSize != statbuf.st_size) { - pLastFileInfo->fileSize = statbuf.st_size; + if (oldSz != newSz || pLastFileInfo->fileSize != file_size) { + pLastFileInfo->fileSize = file_size; pWal->vers.lastVer = walScanLogGetLastVer(pWal); ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer; ASSERT(pWal->vers.lastVer != -1); @@ -395,9 +395,9 @@ int walLoadMeta(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer, fnameStr); // read metafile - struct stat statbuf; - stat(fnameStr, &statbuf); - int size = statbuf.st_size; + int64_t file_size = 0; + taosStatFile(fnameStr, &file_size, NULL); + int size = (int)file_size; char* buf = malloc(size + 5); if (buf == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 91ef97e66b..e0f5f80dab 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -60,7 +60,7 @@ void taosRemoveDir(const char *dirname) { //printf("dir:%s is removed\n", dirname); } -int32_t taosDirExist(char *dirname) { return access(dirname, F_OK); } +bool taosDirExist(char *dirname) { return taosCheckExistFile(dirname); } int32_t taosMkDir(const char *dirname) { int32_t code = mkdir(dirname, 0755); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index c2e9b52f88..37004e9d70 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -186,6 +186,27 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { return 0; #endif } +int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + return 0; +#else + struct stat fileStat; + int32_t code = stat(path, &fileStat); + if (code < 0) { + return code; + } + + if (stDev != NULL) { + *stDev = fileStat.st_dev; + } + + if (stIno != NULL) { + *stIno = fileStat.st_ino; + } + + return 0; +#endif +} void autoDelFileListAdd(const char *path) { return; } @@ -733,3 +754,21 @@ int32_t taosEOFFile(TdFilePtr pFile) { return feof(pFile->fp); } +bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { + int flags = 0; + + if (tdFileAccessOptions & TD_FILE_ACCESS_EXIST_OK) { + flags |= F_OK; + } + + if (tdFileAccessOptions & TD_FILE_ACCESS_READ_OK) { + flags |= R_OK; + } + + if (tdFileAccessOptions & TD_FILE_ACCESS_WRITE_OK) { + flags |= W_OK; + } + + return access(pathname, flags) == 0; +} +bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; \ No newline at end of file diff --git a/source/util/test/cacheTest.cpp b/source/util/test/cacheTest.cpp index 970f1c23a9..4dde374bdd 100644 --- a/source/util/test/cacheTest.cpp +++ b/source/util/test/cacheTest.cpp @@ -1,7 +1,7 @@ -#include "os.h" #include #include +#include "os.h" #include "taos.h" #include "tcache.h" diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 5505a6207f..7b993ebf35 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -1,6 +1,6 @@ #include -#include "gtest/gtest.h" +#include #include "tencode.h" diff --git a/source/util/test/freelistTest.cpp b/source/util/test/freelistTest.cpp index cf11d6b5bf..7fd3d693fb 100644 --- a/source/util/test/freelistTest.cpp +++ b/source/util/test/freelistTest.cpp @@ -1,4 +1,4 @@ -#include "gtest/gtest.h" +#include #include "tfreelist.h" diff --git a/source/util/test/hashTest.cpp b/source/util/test/hashTest.cpp index ac1bae2434..4c6ee8d10c 100644 --- a/source/util/test/hashTest.cpp +++ b/source/util/test/hashTest.cpp @@ -1,9 +1,9 @@ -#include "os.h" #include #include -#include #include +#include "os.h" +#include "taosdef.h" #include "thash.h" #include "taos.h" diff --git a/tools/shell/src/backup/shellImport.c b/tools/shell/src/backup/shellImport.c index c0ab7ef461..36489a448b 100644 --- a/tools/shell/src/backup/shellImport.c +++ b/tools/shell/src/backup/shellImport.c @@ -93,8 +93,7 @@ static void shellCheckTablesSQLFile(const char *directoryName) { sprintf(shellTablesSQLFile, "%s/tables.sql", directoryName); - struct stat fstat; - if (stat(shellTablesSQLFile, &fstat) < 0) { + if (taosFStatFile(shellTablesSQLFile, NULL, NULL) < 0) { shellTablesSQLFile[0] = 0; } } @@ -109,13 +108,12 @@ static void shellMallocSQLFiles() static void shellGetDirectoryFileList(char *inputDir) { - struct stat fileStat; - if (stat(inputDir, &fileStat) < 0) { + if (!taosDirExist(inputDir)) { fprintf(stderr, "ERROR: %s not exist\n", inputDir); exit(0); } - if (fileStat.st_mode & S_IFDIR) { + if (taosIsDir(inputDir)) { shellCheckTablesSQLFile(inputDir); shellSQLFileNum = shellGetFilesNum(inputDir, "sql"); int totalSQLFileNum = shellSQLFileNum;