Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Utils Native Lite
提交
c062381b
U
Utils Native Lite
项目概览
OpenHarmony
/
Utils Native Lite
9 个月 前同步成功
通知
2
Star
19
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Utils Native Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c062381b
编写于
9月 20, 2020
作者:
G
Gymee
提交者:
openharmony_ci
9月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
!16 [Lightweight PR]: optimize code by removing redundant code
Merge pull request !16 from Gymee/N/A
上级
f50b76b3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
72 deletion
+43
-72
file/src/file_impl_hal/file.c
file/src/file_impl_hal/file.c
+10
-10
js/builtin/filekit/src/nativeapi_fs_impl.c
js/builtin/filekit/src/nativeapi_fs_impl.c
+27
-49
js/builtin/kvstorekit/src/nativeapi_kv.cpp
js/builtin/kvstorekit/src/nativeapi_kv.cpp
+3
-6
js/builtin/kvstorekit/src/nativeapi_kv_impl.c
js/builtin/kvstorekit/src/nativeapi_kv_impl.c
+3
-7
未找到文件。
file/src/file_impl_hal/file.c
浏览文件 @
c062381b
...
...
@@ -19,6 +19,8 @@
#include "ohos_errno.h"
#include "ohos_types.h"
#include <stdbool.h>
#define BUFFER_SIZE 128
int
UtilsFileOpen
(
const
char
*
path
,
int
oflag
,
int
mode
)
...
...
@@ -70,28 +72,26 @@ int UtilsFileCopy(const char* src, const char* dest)
UtilsFileClose
(
fpSrc
);
return
fpDest
;
}
bool
copyFailed
=
true
;
char
*
dataBuf
=
(
char
*
)
malloc
(
BUFFER_SIZE
);
if
(
dataBuf
==
NULL
)
{
UtilsFileClose
(
fpSrc
);
UtilsFileClose
(
fpDest
);
UtilsFileDelete
(
dest
);
return
EC_FAILURE
;
goto
MALLOC_ERROR
;
}
int
nLen
=
UtilsFileRead
(
fpSrc
,
dataBuf
,
BUFFER_SIZE
);
while
(
nLen
>
0
)
{
if
(
UtilsFileWrite
(
fpDest
,
dataBuf
,
nLen
)
!=
nLen
)
{
free
(
dataBuf
);
UtilsFileClose
(
fpSrc
);
UtilsFileClose
(
fpDest
);
UtilsFileDelete
(
dest
);
return
EC_FAILURE
;
goto
EXIT
;
}
nLen
=
UtilsFileRead
(
fpSrc
,
dataBuf
,
BUFFER_SIZE
);
}
copyFailed
=
(
nLen
<
0
);
EXIT:
free
(
dataBuf
);
MALLOC_ERROR:
UtilsFileClose
(
fpSrc
);
UtilsFileClose
(
fpDest
);
if
(
nLen
<
0
)
{
if
(
copyFailed
)
{
UtilsFileDelete
(
dest
);
return
EC_FAILURE
;
}
...
...
js/builtin/filekit/src/nativeapi_fs_impl.c
浏览文件 @
c062381b
...
...
@@ -69,24 +69,17 @@ static int RmdirRecursive(const char* fileName)
struct
stat
info
=
{
0
};
char
*
fullPath
=
(
char
*
)
malloc
(
FILE_NAME_MAX_LEN
+
1
);
if
(
fullPath
==
NULL
)
{
closedir
(
fileDir
);
return
ret
;
goto
MALLOC_ERROR
;
}
while
(
dir
!=
NULL
)
{
if
(
memset_s
(
fullPath
,
FILE_NAME_MAX_LEN
+
1
,
0x0
,
FILE_NAME_MAX_LEN
+
1
)
!=
EOK
)
{
free
(
fullPath
);
closedir
(
fileDir
);
return
ret
;
goto
EXIT
;
}
if
(
sprintf_s
(
fullPath
,
FILE_NAME_MAX_LEN
+
1
,
"%s/%s"
,
fileName
,
dir
->
d_name
)
<
0
)
{
free
(
fullPath
);
closedir
(
fileDir
);
return
ret
;
goto
EXIT
;
}
if
(
stat
(
fullPath
,
&
info
)
!=
0
)
{
free
(
fullPath
);
closedir
(
fileDir
);
return
ret
;
goto
EXIT
;
}
if
(
S_ISDIR
(
info
.
st_mode
))
{
ret
=
RmdirRecursive
(
fullPath
);
...
...
@@ -94,15 +87,17 @@ static int RmdirRecursive(const char* fileName)
ret
=
unlink
(
fullPath
);
}
if
(
ret
!=
NATIVE_SUCCESS
)
{
free
(
fullPath
);
closedir
(
fileDir
);
return
ret
;
goto
EXIT
;
}
dir
=
readdir
(
fileDir
);
}
ret
=
rmdir
(
fileName
);
EXIT:
free
(
fullPath
);
MALLOC_ERROR:
closedir
(
fileDir
);
return
r
mdir
(
fileName
)
;
return
r
et
;
}
static
int
MakeParent
(
const
char
*
path
,
char
*
firstPath
,
size_t
fPathLen
,
int
*
dirNum
)
...
...
@@ -175,10 +170,7 @@ static int DoCopyFile(int fdSrc, int fdDest)
nLen
=
read
(
fdSrc
,
dataBuf
,
BUFFER_SIZE
);
}
free
(
dataBuf
);
if
(
nLen
<
0
)
{
return
ERROR_CODE_IO
;
}
return
NATIVE_SUCCESS
;
return
(
nLen
<
0
)
?
ERROR_CODE_IO
:
NATIVE_SUCCESS
;
}
int
StatImpl
(
const
char
*
path
,
struct
stat
*
buf
)
...
...
@@ -186,8 +178,8 @@ int StatImpl(const char* path, struct stat* buf)
if
(
!
IsValidPath
(
path
)
||
(
buf
==
NULL
))
{
return
ERROR_CODE_PARAM
;
}
int
ret
=
stat
(
path
,
buf
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
if
(
stat
(
path
,
buf
)
!=
NATIVE_SUCCESS
)
{
return
(
-
errno
);
}
return
NATIVE_SUCCESS
;
...
...
@@ -198,8 +190,8 @@ int DeleteFileImpl(const char* src)
if
(
!
IsValidPath
(
src
))
{
return
ERROR_CODE_PARAM
;
}
int
ret
=
unlink
(
src
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
if
(
unlink
(
src
)
!=
NATIVE_SUCCESS
)
{
return
(
-
errno
);
}
return
NATIVE_SUCCESS
;
...
...
@@ -242,11 +234,11 @@ int CopyFileImpl(const char* src, const char* dest)
return
(
-
errno
);
}
int
ret
=
DoCopyFile
(
fdSrc
,
fdDest
);
close
(
fdSrc
);
close
(
fdDest
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
unlink
(
dest
);
}
close
(
fdSrc
);
close
(
fdDest
);
return
ret
;
}
...
...
@@ -273,12 +265,9 @@ int WriteTextFile(const char* fileName, const void* buf, size_t len, bool append
if
(
fileHandle
<
0
)
{
return
(
-
errno
);
}
if
(
write
(
fileHandle
,
buf
,
len
)
!=
len
)
{
close
(
fileHandle
);
return
ERROR_CODE_IO
;
}
int
writeLen
=
write
(
fileHandle
,
buf
,
len
);
close
(
fileHandle
);
return
NATIVE_SUCCESS
;
return
(
writeLen
!=
len
)
?
ERROR_CODE_IO
:
NATIVE_SUCCESS
;
}
int
WriteArrayFile
(
const
char
*
fileName
,
const
void
*
buf
,
size_t
len
,
unsigned
int
position
,
bool
append
)
...
...
@@ -314,12 +303,9 @@ int WriteArrayFile(const char* fileName, const void* buf, size_t len, unsigned i
return
ERROR_CODE_IO
;
}
}
if
(
write
(
fileHandle
,
buf
,
len
)
!=
len
)
{
close
(
fileHandle
);
return
ERROR_CODE_IO
;
}
int
writeLen
=
write
(
fileHandle
,
buf
,
len
);
close
(
fileHandle
);
return
NATIVE_SUCCESS
;
return
(
writeLen
!=
len
)
?
ERROR_CODE_IO
:
NATIVE_SUCCESS
;
}
int
ReadFileImpl
(
const
char
*
fileName
,
void
*
text
,
size_t
len
,
unsigned
int
position
,
size_t
*
actualLen
)
...
...
@@ -358,13 +344,9 @@ int ReadFileImpl(const char* fileName, void* text, size_t len, unsigned int posi
return
ERROR_CODE_IO
;
}
int
readLen
=
read
(
fileHandle
,
text
,
len
);
*
actualLen
=
readLen
;
if
(
readLen
<
0
)
{
close
(
fileHandle
);
return
ERROR_CODE_IO
;
}
close
(
fileHandle
);
return
NATIVE_SUCCESS
;
*
actualLen
=
readLen
;
return
(
readLen
<
0
)
?
ERROR_CODE_IO
:
NATIVE_SUCCESS
;
}
int
GetFileListImpl
(
const
char
*
dirName
,
FileMetaInfo
*
fileList
,
unsigned
int
listNum
)
...
...
@@ -427,10 +409,7 @@ int GetFileNum(const char* dirName)
dir
=
readdir
(
fileDir
);
}
closedir
(
fileDir
);
if
(
sum
==
0
)
{
return
ERROR_CODE_IO
;
}
return
sum
;
return
(
sum
==
0
)
?
ERROR_CODE_IO
:
sum
;
}
int
AccessImpl
(
const
char
*
fileName
)
...
...
@@ -455,8 +434,8 @@ int CreateDirImpl(const char* fileName, bool recursive)
if
(
recursive
)
{
return
MkdirRecursive
(
fileName
);
}
int
ret
=
mkdir
(
fileName
,
S_IRUSR
|
S_IWUSR
|
S_IXUSR
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
if
(
mkdir
(
fileName
,
S_IRUSR
|
S_IWUSR
|
S_IXUSR
)
!=
NATIVE_SUCCESS
)
{
return
(
-
errno
);
}
return
NATIVE_SUCCESS
;
...
...
@@ -471,8 +450,7 @@ int RemoveDirImpl(const char* fileName, bool recursive)
if
(
recursive
)
{
return
RmdirRecursive
(
fileName
);
}
ret
=
rmdir
(
fileName
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
if
(
rmdir
(
fileName
)
!=
NATIVE_SUCCESS
)
{
return
(
-
errno
);
}
return
NATIVE_SUCCESS
;
...
...
js/builtin/kvstorekit/src/nativeapi_kv.cpp
浏览文件 @
c062381b
...
...
@@ -75,8 +75,7 @@ int GetValueInner(const char* dataPath, const char* key, char* value)
if
(
ret
!=
NATIVE_SUCCESS
)
{
return
ret
;
}
ret
=
GetValue
(
g_kvFullPath
,
value
);
return
ret
;
return
GetValue
(
g_kvFullPath
,
value
);
}
int
SetValueInner
(
const
char
*
dataPath
,
const
char
*
key
,
const
char
*
value
)
...
...
@@ -85,8 +84,7 @@ int SetValueInner(const char* dataPath, const char* key, const char* value)
if
(
ret
!=
NATIVE_SUCCESS
)
{
return
ret
;
}
ret
=
SetValue
(
g_kvFullPath
,
value
);
return
ret
;
return
SetValue
(
g_kvFullPath
,
value
);
}
int
DeleteValueInner
(
const
char
*
dataPath
,
const
char
*
key
)
...
...
@@ -95,8 +93,7 @@ int DeleteValueInner(const char* dataPath, const char* key)
if
(
ret
!=
NATIVE_SUCCESS
)
{
return
ret
;
}
ret
=
DeleteValue
(
g_kvFullPath
);
return
ret
;
return
DeleteValue
(
g_kvFullPath
);
}
JSIValue
ExecuteAsyncWork
(
const
JSIValue
thisVal
,
const
JSIValue
*
args
,
...
...
js/builtin/kvstorekit/src/nativeapi_kv_impl.c
浏览文件 @
c062381b
...
...
@@ -129,12 +129,9 @@ int SetValue(const char* key, const char* value)
if
(
fd
<
0
)
{
return
(
-
errno
);
}
if
(
write
(
fd
,
value
,
strlen
(
value
))
<
0
)
{
close
(
fd
);
return
ERROR_CODE_IO
;
}
int
ret
=
write
(
fd
,
value
,
strlen
(
value
));
close
(
fd
);
return
NATIVE_SUCCESS
;
return
(
ret
<
0
)
?
ERROR_CODE_IO
:
NATIVE_SUCCESS
;
}
int
DeleteValue
(
const
char
*
key
)
...
...
@@ -142,8 +139,7 @@ int DeleteValue(const char* key)
if
(
key
==
NULL
)
{
return
ERROR_CODE_PARAM
;
}
int
ret
=
unlink
(
key
);
if
(
ret
!=
NATIVE_SUCCESS
)
{
if
(
unlink
(
key
)
!=
NATIVE_SUCCESS
)
{
return
(
-
errno
);
}
return
NATIVE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录