Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
df65ceb7
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
df65ceb7
编写于
7月 12, 2019
作者:
G
groot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean code
Former-commit-id: 90d01e6fb68342e83c07aac02365f13fd87d67c8
上级
0bd01e74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
33 deletion
+33
-33
cpp/src/utils/CommonUtil.cpp
cpp/src/utils/CommonUtil.cpp
+31
-31
cpp/src/utils/CommonUtil.h
cpp/src/utils/CommonUtil.h
+2
-2
未找到文件。
cpp/src/utils/CommonUtil.cpp
浏览文件 @
df65ceb7
...
...
@@ -32,21 +32,21 @@ namespace server {
namespace
fs
=
boost
::
filesystem
;
bool
CommonUtil
::
GetSystemMemInfo
(
unsigned
long
&
total
Mem
,
unsigned
long
&
freeM
em
)
{
bool
CommonUtil
::
GetSystemMemInfo
(
unsigned
long
&
total
_mem
,
unsigned
long
&
free_m
em
)
{
struct
sysinfo
info
;
int
ret
=
sysinfo
(
&
info
);
total
M
em
=
info
.
totalram
;
free
M
em
=
info
.
freeram
;
total
_m
em
=
info
.
totalram
;
free
_m
em
=
info
.
freeram
;
return
ret
==
0
;
//succeed 0, failed -1
}
bool
CommonUtil
::
GetSystemAvailableThreads
(
unsigned
int
&
thread
C
nt
)
{
bool
CommonUtil
::
GetSystemAvailableThreads
(
unsigned
int
&
thread
_cou
nt
)
{
//threadCnt = std::thread::hardware_concurrency();
thread
C
nt
=
sysconf
(
_SC_NPROCESSORS_CONF
);
thread
C
nt
*=
THREAD_MULTIPLY_CPU
;
if
(
thread
C
nt
==
0
)
thread
C
nt
=
8
;
thread
_cou
nt
=
sysconf
(
_SC_NPROCESSORS_CONF
);
thread
_cou
nt
*=
THREAD_MULTIPLY_CPU
;
if
(
thread
_cou
nt
==
0
)
thread
_cou
nt
=
8
;
return
true
;
}
...
...
@@ -66,9 +66,9 @@ ServerError CommonUtil::CreateDirectory(const std::string &path) {
return
SERVER_SUCCESS
;
}
struct
stat
directory
S
tat
;
int
stat
OK
=
stat
(
path
.
c_str
(),
&
directoryS
tat
);
if
(
stat
OK
==
0
)
{
struct
stat
directory
_s
tat
;
int
stat
us
=
stat
(
path
.
c_str
(),
&
directory_s
tat
);
if
(
stat
us
==
0
)
{
return
SERVER_SUCCESS
;
//already exist
}
...
...
@@ -79,8 +79,8 @@ ServerError CommonUtil::CreateDirectory(const std::string &path) {
return
err
;
}
stat
OK
=
stat
(
path
.
c_str
(),
&
directoryS
tat
);
if
(
stat
OK
==
0
)
{
stat
us
=
stat
(
path
.
c_str
(),
&
directory_s
tat
);
if
(
stat
us
==
0
)
{
return
SERVER_SUCCESS
;
//already exist
}
...
...
@@ -94,29 +94,29 @@ ServerError CommonUtil::CreateDirectory(const std::string &path) {
namespace
{
void
RemoveDirectory
(
const
std
::
string
&
path
)
{
DIR
*
pDir
=
NULL
;
DIR
*
dir
=
nullptr
;
struct
dirent
*
dmsg
;
char
szFileN
ame
[
256
];
char
szFolderN
ame
[
256
];
char
file_n
ame
[
256
];
char
folder_n
ame
[
256
];
strcpy
(
szFolderN
ame
,
path
.
c_str
());
strcat
(
szFolderN
ame
,
"/%s"
);
if
((
pDir
=
opendir
(
path
.
c_str
()))
!=
NULL
)
{
while
((
dmsg
=
readdir
(
pDir
))
!=
NULL
)
{
strcpy
(
folder_n
ame
,
path
.
c_str
());
strcat
(
folder_n
ame
,
"/%s"
);
if
((
dir
=
opendir
(
path
.
c_str
()))
!=
nullptr
)
{
while
((
dmsg
=
readdir
(
dir
))
!=
nullptr
)
{
if
(
strcmp
(
dmsg
->
d_name
,
"."
)
!=
0
&&
strcmp
(
dmsg
->
d_name
,
".."
)
!=
0
)
{
sprintf
(
szFileName
,
szFolderN
ame
,
dmsg
->
d_name
);
std
::
string
tmp
=
szFileN
ame
;
sprintf
(
file_name
,
folder_n
ame
,
dmsg
->
d_name
);
std
::
string
tmp
=
file_n
ame
;
if
(
tmp
.
find
(
"."
)
==
std
::
string
::
npos
)
{
RemoveDirectory
(
szFileN
ame
);
RemoveDirectory
(
file_n
ame
);
}
remove
(
szFileN
ame
);
remove
(
file_n
ame
);
}
}
}
if
(
pDir
!=
NULL
)
{
closedir
(
pD
ir
);
if
(
dir
!=
nullptr
)
{
closedir
(
d
ir
);
}
remove
(
path
.
c_str
());
}
...
...
@@ -127,8 +127,8 @@ ServerError CommonUtil::DeleteDirectory(const std::string &path) {
return
SERVER_SUCCESS
;
}
struct
stat
directory
S
tat
;
int
statOK
=
stat
(
path
.
c_str
(),
&
directory
S
tat
);
struct
stat
directory
_s
tat
;
int
statOK
=
stat
(
path
.
c_str
(),
&
directory
_s
tat
);
if
(
statOK
!=
0
)
return
SERVER_SUCCESS
;
...
...
@@ -141,11 +141,11 @@ bool CommonUtil::IsFileExist(const std::string &path) {
}
uint64_t
CommonUtil
::
GetFileSize
(
const
std
::
string
&
path
)
{
struct
stat
file
I
nfo
;
if
(
stat
(
path
.
c_str
(),
&
file
I
nfo
)
<
0
)
{
struct
stat
file
_i
nfo
;
if
(
stat
(
path
.
c_str
(),
&
file
_i
nfo
)
<
0
)
{
return
0
;
}
else
{
return
(
uint64_t
)
file
I
nfo
.
st_size
;
return
(
uint64_t
)
file
_i
nfo
.
st_size
;
}
}
...
...
cpp/src/utils/CommonUtil.h
浏览文件 @
df65ceb7
...
...
@@ -16,8 +16,8 @@ namespace server {
class
CommonUtil
{
public:
static
bool
GetSystemMemInfo
(
unsigned
long
&
total
Mem
,
unsigned
long
&
freeM
em
);
static
bool
GetSystemAvailableThreads
(
unsigned
int
&
thread
C
nt
);
static
bool
GetSystemMemInfo
(
unsigned
long
&
total
_mem
,
unsigned
long
&
free_m
em
);
static
bool
GetSystemAvailableThreads
(
unsigned
int
&
thread
_cou
nt
);
static
bool
IsFileExist
(
const
std
::
string
&
path
);
static
uint64_t
GetFileSize
(
const
std
::
string
&
path
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录