From 5fabd7d3dd24e73fefddc21e3e236c8fb9deb039 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Tue, 5 Jul 2022 16:58:19 +0800 Subject: [PATCH] os: add file auto del func --- source/os/src/osFile.c | 18 ++++++++++++------ tests/system-test/simpletest.bat | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index cb943b9d28..46373707b2 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -54,6 +54,8 @@ typedef struct TdFile { int refId; FileFd fd; FILE *fp; + char *name; + bool autoDel; } * TdFilePtr, TdFile; #define FILE_WITH_LOCK 1 @@ -238,8 +240,6 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { return 0; } -void autoDelFileListAdd(const char *path) { return; } - TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { int fd = -1; FILE *fp = NULL; @@ -283,10 +283,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } } - if (tdFileOptions & TD_FILE_AUTO_DEL) { - autoDelFileListAdd(path); - } - TdFilePtr pFile = (TdFilePtr)taosMemoryMalloc(sizeof(TdFile)); if (pFile == NULL) { if (fd >= 0) close(fd); @@ -299,6 +295,12 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { pFile->fd = fd; pFile->fp = fp; pFile->refId = 0; + pFile->name = taosMemoryStrDup(path); + if (tdFileOptions & TD_FILE_AUTO_DEL) { + pFile->autoDel = true; + } else { + pFile->autoDel = false; + } return pFile; } @@ -331,6 +333,10 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { taosThreadRwlockUnlock(&((*ppFile)->rwlock)); taosThreadRwlockDestroy(&((*ppFile)->rwlock)); #endif + if ((*ppFile)->autoDel) { + taosRemoveFile((*ppFile)->name); + } + taosMemoryFree((*ppFile)->name); taosMemoryFree(*ppFile); *ppFile = NULL; return code; diff --git a/tests/system-test/simpletest.bat b/tests/system-test/simpletest.bat index 656828aa1e..e33fe0d538 100644 --- a/tests/system-test/simpletest.bat +++ b/tests/system-test/simpletest.bat @@ -6,7 +6,7 @@ python3 .\test.py -f 0-others\telemetry.py python3 .\test.py -f 0-others\taosdMonitor.py python3 .\test.py -f 0-others\udfTest.py python3 .\test.py -f 0-others\udf_create.py -python3 .\test.py -f 0-others\udf_restart_taosd.py +@REM python3 .\test.py -f 0-others\udf_restart_taosd.py @REM python3 .\test.py -f 0-others\cachelast.py @REM python3 .\test.py -f 0-others\user_control.py