提交 35b3edae 编写于 作者: wafwerar's avatar wafwerar

[TD-13756]<fix>: file system stat access func.

上级 d9072005
...@@ -21,7 +21,7 @@ extern "C" { ...@@ -21,7 +21,7 @@ extern "C" {
#endif #endif
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
int32_t taosDirExist(char *dirname); bool taosDirExist(char *dirname);
int32_t taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
void taosRemoveOldFiles(const char *dirname, int32_t keepDays); void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
......
...@@ -25,8 +25,12 @@ extern "C" { ...@@ -25,8 +25,12 @@ extern "C" {
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
#define open OPEN_FUNC_TAOS_FORBID #define open OPEN_FUNC_TAOS_FORBID
#define fopen FOPEN_FUNC_TAOS_FORBID #define fopen FOPEN_FUNC_TAOS_FORBID
// #define close CLOSE_FUNC_TAOS_FORBID #define access ACCESS_FUNC_TAOS_FORBID
// #define fclose FCLOSE_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 #endif
#ifndef PATH_MAX #ifndef PATH_MAX
...@@ -44,6 +48,12 @@ typedef struct TdFile *TdFilePtr; ...@@ -44,6 +48,12 @@ typedef struct TdFile *TdFilePtr;
#define TD_FILE_AUTO_DEL 0x0040 #define TD_FILE_AUTO_DEL 0x0040
#define TD_FILE_EXCL 0x0080 #define TD_FILE_EXCL 0x0080
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosGetLineFile, taosEOFFile #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 taosLockFile(TdFilePtr pFile);
int32_t taosUnLockFile(TdFilePtr pFile); int32_t taosUnLockFile(TdFilePtr pFile);
...@@ -51,9 +61,9 @@ int32_t taosUnLockFile(TdFilePtr pFile); ...@@ -51,9 +61,9 @@ int32_t taosUnLockFile(TdFilePtr pFile);
int32_t taosUmaskFile(int32_t maskVal); int32_t taosUmaskFile(int32_t maskVal);
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime); 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); int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
bool taosCheckExistFile(const char *pathname);
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence); int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence);
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length); int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length);
...@@ -79,7 +89,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in ...@@ -79,7 +89,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length); void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
bool taosValidFile(TdFilePtr pFile); bool taosValidFile(TdFilePtr pFile);
int taosGetErrorFile(TdFilePtr pFile); int32_t taosGetErrorFile(TdFilePtr pFile);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
#include "tcommon.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tep.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -10,6 +8,8 @@ ...@@ -10,6 +8,8 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h" #include "os.h"
#include "tep.h"
#include "tcommon.h"
#include "taos.h" #include "taos.h"
#include "tvariant.h" #include "tvariant.h"
#include "tdef.h" #include "tdef.h"
......
#include <iostream> #include <iostream>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "tmsg.h" #include "tmsg.h"
......
...@@ -90,7 +90,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ...@@ -90,7 +90,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
char name[pathLen + 10]; char name[pathLen + 10];
strcpy(name, path); strcpy(name, path);
if (taosDirExist(name) != 0 && taosMkDir(name) != 0) { if (!taosDirExist(name) && taosMkDir(name) != 0) {
terrno = TSDB_CODE_TQ_FAILED_TO_CREATE_DIR; terrno = TSDB_CODE_TQ_FAILED_TO_CREATE_DIR;
tqError("failed to create dir:%s since %s ", name, terrstr()); tqError("failed to create dir:%s since %s ", name, terrstr());
} }
......
...@@ -580,7 +580,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid ...@@ -580,7 +580,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
SDFile *pRSmadF = TSDB_READ_SMAD_FILE(&(pCommith->readh)); SDFile *pRSmadF = TSDB_READ_SMAD_FILE(&(pCommith->readh));
SDFile *pWSmadF = TSDB_COMMIT_SMAD_FILE(pCommith); 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)); 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); 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 ...@@ -614,7 +614,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
SDFile *pRSmalF = TSDB_READ_SMAL_FILE(&(pCommith->readh)); SDFile *pRSmalF = TSDB_READ_SMAL_FILE(&(pCommith->readh));
SDFile *pWSmalF = TSDB_COMMIT_SMAL_FILE(pCommith); 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); tsdbInitDFileEx(pWSmalF, pRSmalF);
if (tsdbOpenDFile(pWSmalF, O_RDWR) < 0) { 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), tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
......
...@@ -314,7 +314,7 @@ int tsdbOpenFS(STsdb *pRepo) { ...@@ -314,7 +314,7 @@ int tsdbOpenFS(STsdb *pRepo) {
tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current); tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current);
tsdbGetRtnSnap(pRepo, &pRepo->rtn); tsdbGetRtnSnap(pRepo, &pRepo->rtn);
if (access(current, F_OK) == 0) { if (taosCheckExistFile(current)) {
if (tsdbOpenFSFromCurrent(pRepo) < 0) { if (tsdbOpenFSFromCurrent(pRepo) < 0) {
tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno)); tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1; return -1;
......
...@@ -443,25 +443,24 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) { ...@@ -443,25 +443,24 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) {
} }
static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) { static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
struct stat dfstat;
SDFile df; SDFile df;
tsdbInitDFileEx(&df, pDFile); 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), tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pDFile)); TSDB_FILE_FULL_NAME(pDFile));
// pRepo->state |= TSDB_STATE_BAD_DATA; // pRepo->state |= TSDB_STATE_BAD_DATA;
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
return 0; return 0;
} }
int64_t file_size = 0;
if (stat(TSDB_FILE_FULL_NAME(&df), &dfstat) < 0) { if (taosStatFile(TSDB_FILE_FULL_NAME(&df), &file_size, NULL) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
if (pDFile->info.size < dfstat.st_size) { if (pDFile->info.size < file_size) {
// if (tsdbOpenDFile(&df, O_WRONLY) < 0) { // if (tsdbOpenDFile(&df, O_WRONLY) < 0) {
if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) { if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) {
return -1; return -1;
...@@ -480,10 +479,10 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) { ...@@ -480,10 +479,10 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
tsdbCloseDFile(&df); tsdbCloseDFile(&df);
tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), 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); file_size, pDFile->info.size);
} else if (pDFile->info.size > dfstat.st_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", 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; // pRepo->state |= TSDB_STATE_BAD_DATA;
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED; terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
......
add_definitions("-D ALLOW_FORBID_FUNC")
add_subdirectory(transport) add_subdirectory(transport)
add_subdirectory(sync) add_subdirectory(sync)
add_subdirectory(tdb) add_subdirectory(tdb)
......
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#include "os.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
...@@ -24,8 +22,10 @@ ...@@ -24,8 +22,10 @@
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h>
#include "addr_any.h" #include "os.h"
#include "tglobal.h"
#include "catalog.h" #include "catalog.h"
#include "stub.h" #include "stub.h"
#include "taos.h" #include "taos.h"
......
...@@ -2215,10 +2215,10 @@ static void destroyTsComp(STaskRuntimeEnv *pRuntimeEnv, STaskAttr *pQueryAttr) { ...@@ -2215,10 +2215,10 @@ static void destroyTsComp(STaskRuntimeEnv *pRuntimeEnv, STaskAttr *pQueryAttr) {
if (pQueryAttr->tsCompQuery && pRuntimeEnv->outputBuf && pRuntimeEnv->outputBuf->pDataBlock && taosArrayGetSize(pRuntimeEnv->outputBuf->pDataBlock) > 0) { if (pQueryAttr->tsCompQuery && pRuntimeEnv->outputBuf && pRuntimeEnv->outputBuf->pDataBlock && taosArrayGetSize(pRuntimeEnv->outputBuf->pDataBlock) > 0) {
SColumnInfoData* pColInfoData = taosArrayGet(pRuntimeEnv->outputBuf->pDataBlock, 0); SColumnInfoData* pColInfoData = taosArrayGet(pRuntimeEnv->outputBuf->pDataBlock, 0);
if (pColInfoData) { if (pColInfoData) {
FILE *f = *(FILE **)pColInfoData->pData; // TODO refactor TdFilePtr pFile = *(TdFilePtr *)pColInfoData->pData; // TODO refactor
if (f) { if (pFile != NULL) {
fclose(f); taosCloseFile(&pFile);
*(FILE **)pColInfoData->pData = NULL; *(TdFilePtr *)pColInfoData->pData = NULL;
} }
} }
} }
......
...@@ -13,10 +13,7 @@ ...@@ -13,10 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <executorimpl.h>
#include <function.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -26,6 +23,9 @@ ...@@ -26,6 +23,9 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "executorimpl.h"
#include "function.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <executorimpl.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h> #include <tglobal.h>
#include <tsort.h> #include <tsort.h>
...@@ -26,6 +25,7 @@ ...@@ -26,6 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h" #include "os.h"
#include "executorimpl.h"
#include "executor.h" #include "executor.h"
#include "stub.h" #include "stub.h"
#include "taos.h" #include "taos.h"
......
...@@ -63,9 +63,9 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off ...@@ -63,9 +63,9 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
} }
static int writeCtxGetSize(WriterCtx* ctx) { static int writeCtxGetSize(WriterCtx* ctx) {
if (ctx->type == TFile) { if (ctx->type == TFile) {
struct stat fstat; int64_t file_size = 0;
stat(ctx->file.buf, &fstat); taosStatFile(ctx->file.buf, &file_size, NULL);
return fstat.st_size; return (int)file_size;
} }
return 0; return 0;
} }
...@@ -99,9 +99,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ...@@ -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 = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
ctx->file.pFile = taosOpenFile(path, TD_FILE_READ); ctx->file.pFile = taosOpenFile(path, TD_FILE_READ);
struct stat fstat; int64_t file_size = 0;
stat(path, &fstat); taosFStatFile(ctx->file.pFile, &file_size, NULL);
ctx->file.size = fstat.st_size; ctx->file.size = (int)file_size;
#ifdef USE_MMAP #ifdef USE_MMAP
ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.pFile, ctx->file.size); ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.pFile, ctx->file.size);
#endif #endif
...@@ -142,8 +142,10 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { ...@@ -142,8 +142,10 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
#endif #endif
} }
if (ctx->file.readOnly == false) { if (ctx->file.readOnly == false) {
struct stat fstat; int64_t file_size = 0;
stat(ctx->file.buf, &fstat); taosStatFile(ctx->file.buf, &file_size, NULL);
// struct stat fstat;
// stat(ctx->file.buf, &fstat);
// indexError("write file size: %d", (int)(fstat.st_size)); // indexError("write file size: %d", (int)(fstat.st_size));
} }
if (remove) { unlink(ctx->file.buf); } if (remove) { unlink(ctx->file.buf); }
......
...@@ -13,19 +13,17 @@ ...@@ -13,19 +13,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "mockCatalog.h"
#include <iostream> #include <iostream>
#include "stub.h" #include "stub.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#include "addr_any.h" #include <addr_any.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "mockCatalog.h"
namespace { namespace {
void generateTestT1(MockCatalogService* mcs) { void generateTestT1(MockCatalogService* mcs) {
......
...@@ -13,10 +13,8 @@ ...@@ -13,10 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <function.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
#include "tglobal.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
...@@ -25,6 +23,8 @@ ...@@ -25,6 +23,8 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h" #include "os.h"
#include "function.h"
#include "tglobal.h"
#include "astGenerator.h" #include "astGenerator.h"
#include "parserInt.h" #include "parserInt.h"
#include "taos.h" #include "taos.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <function.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h> #include <tglobal.h>
#include <iostream> #include <iostream>
...@@ -25,6 +24,7 @@ ...@@ -25,6 +24,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h" #include "os.h"
#include "function.h"
#include "astGenerator.h" #include "astGenerator.h"
#include "parserInt.h" #include "parserInt.h"
#include "taos.h" #include "taos.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -26,9 +25,11 @@ ...@@ -26,9 +25,11 @@
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
...@@ -37,7 +38,6 @@ ...@@ -37,7 +38,6 @@
#include "planner.h" #include "planner.h"
#include "qworker.h" #include "qworker.h"
#include "stub.h" #include "stub.h"
#include "addr_any.h"
#include "executor.h" #include "executor.h"
#include "dataSinkMgt.h" #include "dataSinkMgt.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -26,15 +25,16 @@ ...@@ -26,15 +25,16 @@
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
#include "tep.h" #include "tep.h"
#include "stub.h" #include "stub.h"
#include "addr_any.h"
#include "scalar.h" #include "scalar.h"
#include "nodes.h" #include "nodes.h"
#include "tlog.h" #include "tlog.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -26,15 +25,16 @@ ...@@ -26,15 +25,16 @@
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
#include "tep.h" #include "tep.h"
#include "stub.h" #include "stub.h"
#include "addr_any.h"
#include "scalar.h" #include "scalar.h"
#include "nodes.h" #include "nodes.h"
#include "tlog.h" #include "tlog.h"
......
...@@ -14,11 +14,21 @@ ...@@ -14,11 +14,21 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h>
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h" #include "taos.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
...@@ -26,18 +36,8 @@ ...@@ -26,18 +36,8 @@
#include "scheduler.h" #include "scheduler.h"
#include "tep.h" #include "tep.h"
#include "trpc.h" #include "trpc.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wformat"
#include "schedulerInt.h" #include "schedulerInt.h"
#include "stub.h" #include "stub.h"
#include "addr_any.h"
#include "tref.h" #include "tref.h"
namespace { namespace {
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
#include "syncRaftStore.h"
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncRaftStore.h"
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
......
#include <stdio.h> #include <stdio.h>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "syncIO.h" #include "syncIO.h"
#include "syncInt.h" #include "syncInt.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
......
...@@ -90,7 +90,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) { ...@@ -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 // get page file from the env, if not opened yet, open it
pPgFile = NULL; pPgFile = NULL;
snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname); snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname);
fileExist = (tdbCheckFileAccess(fname, TDB_F_OK) == 0); fileExist = taosCheckExistFile(fname);
if (fileExist) { if (fileExist) {
tdbGnrtFileID(dbfname, fileid, false); tdbGnrtFileID(dbfname, fileid, false);
pPgFile = tdbEnvGetPageFile(pEnv, fileid); pPgFile = tdbEnvGetPageFile(pEnv, fileid);
......
...@@ -16,16 +16,16 @@ ...@@ -16,16 +16,16 @@
#include "tdbInt.h" #include "tdbInt.h"
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { 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; return -1;
} }
memset(fileid, 0, TDB_FILE_ID_LEN); memset(fileid, 0, TDB_FILE_ID_LEN);
((uint64_t *)fileid)[0] = (uint64_t)statbuf.st_ino; ((uint64_t *)fileid)[0] = stDev;
((uint64_t *)fileid)[1] = (uint64_t)statbuf.st_dev; ((uint64_t *)fileid)[1] = stIno;
if (unique) { if (unique) {
((uint64_t *)fileid)[2] = rand(); ((uint64_t *)fileid)[2] = rand();
} }
...@@ -33,35 +33,34 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { ...@@ -33,35 +33,34 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
return 0; return 0;
} }
int tdbCheckFileAccess(const char *pathname, int mode) { // int tdbCheckFileAccess(const char *pathname, int mode) {
int flags = 0; // int flags = 0;
if (mode & TDB_F_OK) { // if (mode & TDB_F_OK) {
flags |= F_OK; // flags |= F_OK;
} // }
if (mode & TDB_R_OK) { // if (mode & TDB_R_OK) {
flags |= R_OK; // flags |= R_OK;
} // }
if (mode & TDB_W_OK) { // if (mode & TDB_W_OK) {
flags |= W_OK; // flags |= W_OK;
} // }
return access(pathname, flags); // return access(pathname, flags);
} // }
int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize) { int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize) {
struct stat st;
int ret; int ret;
int64_t file_size = 0;
ret = stat(fname, &st); ret = taosStatFile(fname, &file_size, NULL);
if (ret != 0) { if (ret != 0) {
return -1; return -1;
} }
ASSERT(st.st_size % pgSize == 0); ASSERT(file_size % pgSize == 0);
*pSize = st.st_size / pgSize; *pSize = file_size / pgSize;
return 0; return 0;
} }
\ No newline at end of file
...@@ -30,10 +30,10 @@ extern "C" { ...@@ -30,10 +30,10 @@ extern "C" {
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
#define TDB_F_OK 0x1 // #define TDB_F_OK 0x1
#define TDB_R_OK 0x2 // #define TDB_R_OK 0x2
#define TDB_W_OK 0x4 // #define TDB_W_OK 0x4
int tdbCheckFileAccess(const char *pathname, int mode); // int tdbCheckFileAccess(const char *pathname, int mode);
int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize); int tdbGetFileSize(const char *fname, pgsz_t pgSize, pgno_t *pSize);
......
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "tdb.h" #include "tdb.h"
......
...@@ -389,7 +389,6 @@ static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg) { ...@@ -389,7 +389,6 @@ static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg) {
static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) { static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) {
char dirName[TSDB_FILENAME_LEN] = "\0"; char dirName[TSDB_FILENAME_LEN] = "\0";
struct stat pstat;
if (pCfg->level < 0 || pCfg->level >= TFS_MAX_TIERS) { if (pCfg->level < 0 || pCfg->level >= TFS_MAX_TIERS) {
fError("failed to mount %s to FS since invalid level %d", pCfg->dir, pCfg->level); 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) { ...@@ -422,19 +421,13 @@ static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) {
return -1; 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); fError("failed to mount %s to FS since no R/W access rights", pCfg->dir);
terrno = TSDB_CODE_FS_INVLD_CFG; terrno = TSDB_CODE_FS_INVLD_CFG;
return -1; return -1;
} }
if (stat(dirName, &pstat) < 0) { if (!taosIsDir(dirName)) {
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)) {
fError("failed to mount %s to FS since not a directory", pCfg->dir); fError("failed to mount %s to FS since not a directory", pCfg->dir);
terrno = TSDB_CODE_FS_INVLD_CFG; terrno = TSDB_CODE_FS_INVLD_CFG;
return -1; return -1;
......
...@@ -119,29 +119,29 @@ TEST_F(TfsTest, 03_Dir) { ...@@ -119,29 +119,29 @@ TEST_F(TfsTest, 03_Dir) {
char p1[] = "p1"; char p1[] = "p1";
char ap1[128] = {0}; char ap1[128] = {0};
snprintf(ap1, 128, "%s%s%s", root, TD_DIRSEP, p1); 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(tfsMkdir(pTfs, p1), 0);
EXPECT_EQ(taosDirExist(ap1), 0); EXPECT_EQ(taosDirExist(ap1), 1);
char p2[] = "p2"; char p2[] = "p2";
char ap2[128] = {0}; char ap2[128] = {0};
snprintf(ap2, 128, "%s%s%s", root, TD_DIRSEP, p2); snprintf(ap2, 128, "%s%s%s", root, TD_DIRSEP, p2);
SDiskID did = {0}; SDiskID did = {0};
EXPECT_NE(taosDirExist(ap2), 0); EXPECT_NE(taosDirExist(ap2), 1);
EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0); EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0);
EXPECT_EQ(taosDirExist(ap2), 0); EXPECT_EQ(taosDirExist(ap2), 1);
char p3[] = "p3/p2/p1/p0"; char p3[] = "p3/p2/p1/p0";
char ap3[128] = {0}; char ap3[128] = {0};
snprintf(ap3, 128, "%s%s%s", root, TD_DIRSEP, p3); 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(tfsMkdir(pTfs, p3), 0);
EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0); EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0);
EXPECT_EQ(tfsMkdirRecurAt(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_EQ(tfsRmdir(pTfs, p3), 0);
EXPECT_NE(taosDirExist(ap3), 0); EXPECT_NE(taosDirExist(ap3), 1);
char p45[] = "p5"; char p45[] = "p5";
char p44[] = "p4"; char p44[] = "p4";
...@@ -149,12 +149,12 @@ TEST_F(TfsTest, 03_Dir) { ...@@ -149,12 +149,12 @@ TEST_F(TfsTest, 03_Dir) {
char ap4[128] = {0}; char ap4[128] = {0};
snprintf(ap4, 128, "%s%s%s", root, TD_DIRSEP, p4); 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(tfsMkdirRecurAt(pTfs, p4, did), 0);
EXPECT_EQ(taosDirExist(ap4), 0); EXPECT_EQ(taosDirExist(ap4), 1);
EXPECT_EQ(tfsRename(pTfs, p44, p45), 0); EXPECT_EQ(tfsRename(pTfs, p44, p45), 0);
EXPECT_EQ(tfsRmdir(pTfs, p4), 0); EXPECT_EQ(tfsRmdir(pTfs, p4), 0);
EXPECT_NE(taosDirExist(ap4), 0); EXPECT_NE(taosDirExist(ap4), 1);
tfsClose(pTfs); tfsClose(pTfs);
} }
...@@ -251,9 +251,9 @@ TEST_F(TfsTest, 04_File) { ...@@ -251,9 +251,9 @@ TEST_F(TfsTest, 04_File) {
char af2[128] = {0}; char af2[128] = {0};
snprintf(af2, 128, "%s%s%s", root, TD_DIRSEP, n2); snprintf(af2, 128, "%s%s%s", root, TD_DIRSEP, n2);
EXPECT_EQ(taosDirExist(af2), 0); EXPECT_EQ(taosDirExist(af2), 1);
tfsRemoveFile(&f2); tfsRemoveFile(&f2);
EXPECT_NE(taosDirExist(af2), 0); EXPECT_NE(taosDirExist(af2), 1);
{ {
STfsDir *pDir = tfsOpendir(pTfs, "t3"); STfsDir *pDir = tfsOpendir(pTfs, "t3");
...@@ -529,35 +529,35 @@ TEST_F(TfsTest, 05_MultiDisk) { ...@@ -529,35 +529,35 @@ TEST_F(TfsTest, 05_MultiDisk) {
snprintf(ap22, 128, "%s%s%s", root22, TD_DIRSEP, p1); snprintf(ap22, 128, "%s%s%s", root22, TD_DIRSEP, p1);
char ap23[128] = {0}; char ap23[128] = {0};
snprintf(ap23, 128, "%s%s%s", root23, TD_DIRSEP, p1); snprintf(ap23, 128, "%s%s%s", root23, TD_DIRSEP, p1);
EXPECT_NE(taosDirExist(ap00), 0); EXPECT_NE(taosDirExist(ap00), 1);
EXPECT_NE(taosDirExist(ap01), 0); EXPECT_NE(taosDirExist(ap01), 1);
EXPECT_NE(taosDirExist(ap10), 0); EXPECT_NE(taosDirExist(ap10), 1);
EXPECT_NE(taosDirExist(ap11), 0); EXPECT_NE(taosDirExist(ap11), 1);
EXPECT_NE(taosDirExist(ap12), 0); EXPECT_NE(taosDirExist(ap12), 1);
EXPECT_NE(taosDirExist(ap20), 0); EXPECT_NE(taosDirExist(ap20), 1);
EXPECT_NE(taosDirExist(ap21), 0); EXPECT_NE(taosDirExist(ap21), 1);
EXPECT_NE(taosDirExist(ap22), 0); EXPECT_NE(taosDirExist(ap22), 1);
EXPECT_NE(taosDirExist(ap23), 0); EXPECT_NE(taosDirExist(ap23), 1);
EXPECT_EQ(tfsMkdir(pTfs, p1), 0); EXPECT_EQ(tfsMkdir(pTfs, p1), 0);
EXPECT_EQ(taosDirExist(ap00), 0); EXPECT_EQ(taosDirExist(ap00), 1);
EXPECT_EQ(taosDirExist(ap01), 0); EXPECT_EQ(taosDirExist(ap01), 1);
EXPECT_EQ(taosDirExist(ap10), 0); EXPECT_EQ(taosDirExist(ap10), 1);
EXPECT_EQ(taosDirExist(ap11), 0); EXPECT_EQ(taosDirExist(ap11), 1);
EXPECT_EQ(taosDirExist(ap12), 0); EXPECT_EQ(taosDirExist(ap12), 1);
EXPECT_EQ(taosDirExist(ap20), 0); EXPECT_EQ(taosDirExist(ap20), 1);
EXPECT_EQ(taosDirExist(ap21), 0); EXPECT_EQ(taosDirExist(ap21), 1);
EXPECT_EQ(taosDirExist(ap22), 0); EXPECT_EQ(taosDirExist(ap22), 1);
EXPECT_EQ(taosDirExist(ap23), 0); EXPECT_EQ(taosDirExist(ap23), 1);
EXPECT_EQ(tfsRmdir(pTfs, p1), 0); EXPECT_EQ(tfsRmdir(pTfs, p1), 0);
EXPECT_NE(taosDirExist(ap00), 0); EXPECT_NE(taosDirExist(ap00), 1);
EXPECT_NE(taosDirExist(ap01), 0); EXPECT_NE(taosDirExist(ap01), 1);
EXPECT_NE(taosDirExist(ap10), 0); EXPECT_NE(taosDirExist(ap10), 1);
EXPECT_NE(taosDirExist(ap11), 0); EXPECT_NE(taosDirExist(ap11), 1);
EXPECT_NE(taosDirExist(ap12), 0); EXPECT_NE(taosDirExist(ap12), 1);
EXPECT_NE(taosDirExist(ap20), 0); EXPECT_NE(taosDirExist(ap20), 1);
EXPECT_NE(taosDirExist(ap21), 0); EXPECT_NE(taosDirExist(ap21), 1);
EXPECT_NE(taosDirExist(ap22), 0); EXPECT_NE(taosDirExist(ap22), 1);
EXPECT_NE(taosDirExist(ap23), 0); EXPECT_NE(taosDirExist(ap23), 1);
char p2[] = "p2"; char p2[] = "p2";
char _ap21[128] = {0}; char _ap21[128] = {0};
...@@ -565,22 +565,22 @@ TEST_F(TfsTest, 05_MultiDisk) { ...@@ -565,22 +565,22 @@ TEST_F(TfsTest, 05_MultiDisk) {
SDiskID did = {0}; SDiskID did = {0};
did.level = 2; did.level = 2;
did.id = 1; did.id = 1;
EXPECT_NE(taosDirExist(_ap21), 0); EXPECT_NE(taosDirExist(_ap21), 1);
EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0); EXPECT_EQ(tfsMkdirAt(pTfs, p2, did), 0);
EXPECT_EQ(taosDirExist(_ap21), 0); EXPECT_EQ(taosDirExist(_ap21), 1);
char p3[] = "p3/p2/p1/p0"; char p3[] = "p3/p2/p1/p0";
char _ap12[128] = {0}; char _ap12[128] = {0};
snprintf(_ap12, 128, "%s%s%s", root12, TD_DIRSEP, p3); snprintf(_ap12, 128, "%s%s%s", root12, TD_DIRSEP, p3);
did.level = 1; did.level = 1;
did.id = 2; did.id = 2;
EXPECT_NE(taosDirExist(_ap12), 0); EXPECT_NE(taosDirExist(_ap12), 1);
EXPECT_NE(tfsMkdir(pTfs, p3), 0); EXPECT_NE(tfsMkdir(pTfs, p3), 0);
EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0); EXPECT_NE(tfsMkdirAt(pTfs, p3, did), 0);
EXPECT_EQ(tfsMkdirRecurAt(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_EQ(tfsRmdir(pTfs, p3), 0);
EXPECT_NE(taosDirExist(_ap12), 0); EXPECT_NE(taosDirExist(_ap12), 1);
char p45[] = "p5"; char p45[] = "p5";
char p44[] = "p4"; char p44[] = "p4";
...@@ -590,12 +590,12 @@ TEST_F(TfsTest, 05_MultiDisk) { ...@@ -590,12 +590,12 @@ TEST_F(TfsTest, 05_MultiDisk) {
did.level = 2; did.level = 2;
did.id = 2; did.id = 2;
EXPECT_NE(taosDirExist(_ap22), 0); EXPECT_NE(taosDirExist(_ap22), 1);
EXPECT_EQ(tfsMkdirRecurAt(pTfs, p4, did), 0); 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(tfsRename(pTfs, p44, p45), 0);
EXPECT_EQ(tfsRmdir(pTfs, p4), 0); EXPECT_EQ(tfsRmdir(pTfs, p4), 0);
EXPECT_NE(taosDirExist(_ap22), 0); EXPECT_NE(taosDirExist(_ap22), 1);
} }
//------------- File -----------------// //------------- File -----------------//
...@@ -660,7 +660,7 @@ TEST_F(TfsTest, 05_MultiDisk) { ...@@ -660,7 +660,7 @@ TEST_F(TfsTest, 05_MultiDisk) {
char af2[128] = {0}; char af2[128] = {0};
snprintf(af2, 128, "%s%s%s", root23, TD_DIRSEP, n2); snprintf(af2, 128, "%s%s%s", root23, TD_DIRSEP, n2);
EXPECT_EQ(taosDirExist(af2), 0); EXPECT_EQ(taosDirExist(af2), 1);
tfsRemoveFile(&f2); tfsRemoveFile(&f2);
{ {
...@@ -678,7 +678,7 @@ TEST_F(TfsTest, 05_MultiDisk) { ...@@ -678,7 +678,7 @@ TEST_F(TfsTest, 05_MultiDisk) {
tfsClosedir(pDir); tfsClosedir(pDir);
} }
EXPECT_NE(taosDirExist(af2), 0); EXPECT_NE(taosDirExist(af2), 1);
EXPECT_GT(tfsCopyFile(&f1, &f2), 0); EXPECT_GT(tfsCopyFile(&f1, &f2), 0);
{ {
......
...@@ -64,10 +64,10 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) { ...@@ -64,10 +64,10 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr);
struct stat statbuf; int64_t file_size = 0;
stat(fnameStr, &statbuf); taosStatFile(fnameStr, &file_size, NULL);
int readSize = TMIN(WAL_MAX_SIZE + 2, statbuf.st_size); int readSize = TMIN(WAL_MAX_SIZE + 2, file_size);
pLastFileInfo->fileSize = statbuf.st_size; pLastFileInfo->fileSize = file_size;
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
...@@ -177,11 +177,11 @@ int walCheckAndRepairMeta(SWal* pWal) { ...@@ -177,11 +177,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
SWalFileInfo *pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz-1); SWalFileInfo *pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz-1);
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr);
struct stat statbuf; int64_t file_size = 0;
stat(fnameStr, &statbuf); taosStatFile(fnameStr, &file_size, NULL);
if (oldSz != newSz || pLastFileInfo->fileSize != statbuf.st_size) { if (oldSz != newSz || pLastFileInfo->fileSize != file_size) {
pLastFileInfo->fileSize = statbuf.st_size; pLastFileInfo->fileSize = file_size;
pWal->vers.lastVer = walScanLogGetLastVer(pWal); pWal->vers.lastVer = walScanLogGetLastVer(pWal);
((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer; ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer;
ASSERT(pWal->vers.lastVer != -1); ASSERT(pWal->vers.lastVer != -1);
...@@ -395,9 +395,9 @@ int walLoadMeta(SWal* pWal) { ...@@ -395,9 +395,9 @@ int walLoadMeta(SWal* pWal) {
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildMetaName(pWal, metaVer, fnameStr); walBuildMetaName(pWal, metaVer, fnameStr);
// read metafile // read metafile
struct stat statbuf; int64_t file_size = 0;
stat(fnameStr, &statbuf); taosStatFile(fnameStr, &file_size, NULL);
int size = statbuf.st_size; int size = (int)file_size;
char* buf = malloc(size + 5); char* buf = malloc(size + 5);
if (buf == NULL) { if (buf == NULL) {
terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
......
...@@ -60,7 +60,7 @@ void taosRemoveDir(const char *dirname) { ...@@ -60,7 +60,7 @@ void taosRemoveDir(const char *dirname) {
//printf("dir:%s is removed\n", 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 taosMkDir(const char *dirname) {
int32_t code = mkdir(dirname, 0755); int32_t code = mkdir(dirname, 0755);
......
...@@ -186,6 +186,27 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { ...@@ -186,6 +186,27 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
return 0; return 0;
#endif #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; } void autoDelFileListAdd(const char *path) { return; }
...@@ -733,3 +754,21 @@ int32_t taosEOFFile(TdFilePtr pFile) { ...@@ -733,3 +754,21 @@ int32_t taosEOFFile(TdFilePtr pFile) {
return feof(pFile->fp); 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
#include "os.h"
#include <iostream> #include <iostream>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "os.h"
#include "taos.h" #include "taos.h"
#include "tcache.h" #include "tcache.h"
......
#include <iostream> #include <iostream>
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "tencode.h" #include "tencode.h"
......
#include "gtest/gtest.h" #include <gtest/gtest.h>
#include "tfreelist.h" #include "tfreelist.h"
......
#include "os.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <limits.h> #include <limits.h>
#include <taosdef.h>
#include <iostream> #include <iostream>
#include "os.h"
#include "taosdef.h"
#include "thash.h" #include "thash.h"
#include "taos.h" #include "taos.h"
......
...@@ -93,8 +93,7 @@ static void shellCheckTablesSQLFile(const char *directoryName) ...@@ -93,8 +93,7 @@ static void shellCheckTablesSQLFile(const char *directoryName)
{ {
sprintf(shellTablesSQLFile, "%s/tables.sql", directoryName); sprintf(shellTablesSQLFile, "%s/tables.sql", directoryName);
struct stat fstat; if (taosFStatFile(shellTablesSQLFile, NULL, NULL) < 0) {
if (stat(shellTablesSQLFile, &fstat) < 0) {
shellTablesSQLFile[0] = 0; shellTablesSQLFile[0] = 0;
} }
} }
...@@ -109,13 +108,12 @@ static void shellMallocSQLFiles() ...@@ -109,13 +108,12 @@ static void shellMallocSQLFiles()
static void shellGetDirectoryFileList(char *inputDir) static void shellGetDirectoryFileList(char *inputDir)
{ {
struct stat fileStat; if (!taosDirExist(inputDir)) {
if (stat(inputDir, &fileStat) < 0) {
fprintf(stderr, "ERROR: %s not exist\n", inputDir); fprintf(stderr, "ERROR: %s not exist\n", inputDir);
exit(0); exit(0);
} }
if (fileStat.st_mode & S_IFDIR) { if (taosIsDir(inputDir)) {
shellCheckTablesSQLFile(inputDir); shellCheckTablesSQLFile(inputDir);
shellSQLFileNum = shellGetFilesNum(inputDir, "sql"); shellSQLFileNum = shellGetFilesNum(inputDir, "sql");
int totalSQLFileNum = shellSQLFileNum; int totalSQLFileNum = shellSQLFileNum;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册