Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f93abddc
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f93abddc
编写于
1月 03, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(utility): fix the bug in creating auto delete files.
上级
879205eb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
51 deletion
+17
-51
source/os/src/osFile.c
source/os/src/osFile.c
+17
-51
未找到文件。
source/os/src/osFile.c
浏览文件 @
f93abddc
...
@@ -39,14 +39,6 @@
...
@@ -39,14 +39,6 @@
#define _SEND_FILE_STEP_ 1000
#define _SEND_FILE_STEP_ 1000
#endif
#endif
#if defined(WINDOWS)
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#else
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#endif
typedef
int32_t
FileFd
;
typedef
int32_t
FileFd
;
typedef
struct
TdFile
{
typedef
struct
TdFile
{
...
@@ -54,19 +46,10 @@ typedef struct TdFile {
...
@@ -54,19 +46,10 @@ typedef struct TdFile {
int
refId
;
int
refId
;
FileFd
fd
;
FileFd
fd
;
FILE
*
fp
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
}
TdFile
;
#define FILE_WITH_LOCK 1
#define FILE_WITH_LOCK 1
typedef
struct
AutoDelFile
*
AutoDelFilePtr
;
typedef
struct
AutoDelFile
{
char
*
name
;
AutoDelFilePtr
lastAutoDelFilePtr
;
}
AutoDelFile
;
static
TdThreadMutex
autoDelFileLock
;
static
AutoDelFilePtr
nowAutoDelFilePtr
=
NULL
;
static
TdThreadOnce
autoDelFileInit
=
PTHREAD_ONCE_INIT
;
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
#ifdef WINDOWS
#ifdef WINDOWS
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
...
@@ -268,34 +251,6 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
...
@@ -268,34 +251,6 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
return
0
;
return
0
;
}
}
void
autoDelFileList
()
{
taosThreadMutexLock
(
&
autoDelFileLock
);
while
(
nowAutoDelFilePtr
!=
NULL
)
{
taosRemoveFile
(
nowAutoDelFilePtr
->
name
);
AutoDelFilePtr
tmp
=
nowAutoDelFilePtr
->
lastAutoDelFilePtr
;
taosMemoryFree
(
nowAutoDelFilePtr
->
name
);
taosMemoryFree
(
nowAutoDelFilePtr
);
nowAutoDelFilePtr
=
tmp
;
}
taosThreadMutexUnlock
(
&
autoDelFileLock
);
taosThreadMutexDestroy
(
&
autoDelFileLock
);
}
void
autoDelFileListInit
()
{
taosThreadMutexInit
(
&
autoDelFileLock
,
NULL
);
atexit
(
autoDelFileList
);
}
void
autoDelFileListAdd
(
const
char
*
path
)
{
taosThreadOnce
(
&
autoDelFileInit
,
autoDelFileListInit
);
taosThreadMutexLock
(
&
autoDelFileLock
);
AutoDelFilePtr
tmp
=
taosMemoryMalloc
(
sizeof
(
AutoDelFile
));
tmp
->
lastAutoDelFilePtr
=
nowAutoDelFilePtr
;
tmp
->
name
=
taosMemoryStrDup
(
path
);
nowAutoDelFilePtr
=
tmp
;
taosThreadMutexUnlock
(
&
autoDelFileLock
);
}
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
int
fd
=
-
1
;
int
fd
=
-
1
;
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
...
@@ -313,7 +268,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -313,7 +268,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
assert
(
!
(
tdFileOptions
&
TD_FILE_EXCL
));
assert
(
!
(
tdFileOptions
&
TD_FILE_EXCL
));
fp
=
fopen
(
path
,
mode
);
fp
=
fopen
(
path
,
mode
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
// terrno = TAOS_SYSTEM_ERROR(errno);
return
NULL
;
return
NULL
;
}
}
}
else
{
}
else
{
...
@@ -331,32 +285,44 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -331,32 +285,44 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
access
|=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
O_TEXT
:
0
;
access
|=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
O_TEXT
:
0
;
access
|=
(
tdFileOptions
&
TD_FILE_EXCL
)
?
O_EXCL
:
0
;
access
|=
(
tdFileOptions
&
TD_FILE_EXCL
)
?
O_EXCL
:
0
;
#ifdef WINDOWS
#ifdef WINDOWS
fd
=
_open
(
path
,
access
,
_S_IREAD
|
_S_IWRITE
);
int32_t
pmode
=
_S_IREAD
|
_S_IWRITE
;
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
pmode
|=
_O_TEMPORARY
;
}
fd
=
_open
(
path
,
access
,
pmode
);
#else
#else
fd
=
open
(
path
,
access
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
fd
=
open
(
path
,
access
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
#endif
#endif
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
// terrno = TAOS_SYSTEM_ERROR(errno);
return
NULL
;
return
NULL
;
}
}
}
}
TdFilePtr
pFile
=
(
TdFilePtr
)
taosMemoryMalloc
(
sizeof
(
TdFile
));
TdFilePtr
pFile
=
(
TdFilePtr
)
taosMemoryMalloc
(
sizeof
(
TdFile
));
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// terrno = TSDB_CODE_OUT_OF_MEMORY;
if
(
fd
>=
0
)
close
(
fd
);
if
(
fd
>=
0
)
close
(
fd
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
return
NULL
;
return
NULL
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
taosThreadRwlockInit
(
&
(
pFile
->
rwlock
),
NULL
);
taosThreadRwlockInit
(
&
(
pFile
->
rwlock
),
NULL
);
#endif
#endif
pFile
->
fd
=
fd
;
pFile
->
fd
=
fd
;
pFile
->
fp
=
fp
;
pFile
->
fp
=
fp
;
pFile
->
refId
=
0
;
pFile
->
refId
=
0
;
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
autoDelFileListAdd
(
path
);
#ifdef WINDOWS
// do nothing, since the property of pmode is set with _O_TEMPORARY; the OS will recycle
// the file handle, as well as the space on disk.
#else
// Remove it instantly, so when the program exits normally/abnormally, the file
// will be automatically remove by OS.
unlink
(
path
);
#endif
}
}
return
pFile
;
return
pFile
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录