Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
努力学习的小马
arduino-esp32
提交
b6f0ba86
A
arduino-esp32
项目概览
努力学习的小马
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b6f0ba86
编写于
3月 04, 2021
作者:
M
me-no-dev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS::name() returns the item name as in Arduino SD
Added method FS::path() that returns the full path
上级
7a6900a1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
34 deletion
+51
-34
libraries/FS/src/FS.cpp
libraries/FS/src/FS.cpp
+9
-0
libraries/FS/src/FS.h
libraries/FS/src/FS.h
+1
-0
libraries/FS/src/FSImpl.h
libraries/FS/src/FSImpl.h
+1
-0
libraries/FS/src/vfs_api.cpp
libraries/FS/src/vfs_api.cpp
+39
-34
libraries/FS/src/vfs_api.h
libraries/FS/src/vfs_api.h
+1
-0
未找到文件。
libraries/FS/src/FS.cpp
浏览文件 @
b6f0ba86
...
...
@@ -143,6 +143,15 @@ File::operator bool() const
return
_p
!=
nullptr
&&
*
_p
!=
false
;
}
const
char
*
File
::
path
()
const
{
if
(
!*
this
)
{
return
nullptr
;
}
return
_p
->
path
();
}
const
char
*
File
::
name
()
const
{
if
(
!*
this
)
{
...
...
libraries/FS/src/FS.h
浏览文件 @
b6f0ba86
...
...
@@ -73,6 +73,7 @@ public:
void
close
();
operator
bool
()
const
;
time_t
getLastWrite
();
const
char
*
path
()
const
;
const
char
*
name
()
const
;
boolean
isDirectory
(
void
);
...
...
libraries/FS/src/FSImpl.h
浏览文件 @
b6f0ba86
...
...
@@ -38,6 +38,7 @@ public:
virtual
size_t
size
()
const
=
0
;
virtual
void
close
()
=
0
;
virtual
time_t
getLastWrite
()
=
0
;
virtual
const
char
*
path
()
const
=
0
;
virtual
const
char
*
name
()
const
=
0
;
virtual
boolean
isDirectory
(
void
)
=
0
;
virtual
FileImplPtr
openNextFile
(
const
char
*
mode
)
=
0
;
...
...
libraries/FS/src/vfs_api.cpp
浏览文件 @
b6f0ba86
...
...
@@ -16,41 +16,41 @@
using
namespace
fs
;
FileImplPtr
VFSImpl
::
open
(
const
char
*
path
,
const
char
*
mode
)
FileImplPtr
VFSImpl
::
open
(
const
char
*
f
path
,
const
char
*
mode
)
{
if
(
!
_mountpoint
)
{
log_e
(
"File system is not mounted"
);
return
FileImplPtr
();
}
if
(
!
path
||
path
[
0
]
!=
'/'
)
{
log_e
(
"%s does not start with /"
,
path
);
if
(
!
fpath
||
f
path
[
0
]
!=
'/'
)
{
log_e
(
"%s does not start with /"
,
f
path
);
return
FileImplPtr
();
}
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
path
)
+
strlen
(
_mountpoint
)
+
2
);
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
f
path
)
+
strlen
(
_mountpoint
)
+
2
);
if
(
!
temp
)
{
log_e
(
"malloc failed"
);
return
FileImplPtr
();
}
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
path
);
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
f
path
);
struct
stat
st
;
//file lound
if
(
!
stat
(
temp
,
&
st
))
{
free
(
temp
);
if
(
S_ISREG
(
st
.
st_mode
)
||
S_ISDIR
(
st
.
st_mode
))
{
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
path
,
mode
);
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
f
path
,
mode
);
}
log_e
(
"%s has wrong mode 0x%08X"
,
path
,
st
.
st_mode
);
log_e
(
"%s has wrong mode 0x%08X"
,
f
path
,
st
.
st_mode
);
return
FileImplPtr
();
}
//file not found but mode permits creation
if
(
mode
&&
mode
[
0
]
!=
'r'
)
{
free
(
temp
);
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
path
,
mode
);
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
f
path
,
mode
);
}
//try to open this as directory (might be mount point)
...
...
@@ -58,7 +58,7 @@ FileImplPtr VFSImpl::open(const char* path, const char* mode)
if
(
d
)
{
closedir
(
d
);
free
(
temp
);
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
path
,
mode
);
return
std
::
make_shared
<
VFSFileImpl
>
(
this
,
f
path
,
mode
);
}
log_e
(
"%s does not exist"
,
temp
);
...
...
@@ -66,14 +66,14 @@ FileImplPtr VFSImpl::open(const char* path, const char* mode)
return
FileImplPtr
();
}
bool
VFSImpl
::
exists
(
const
char
*
path
)
bool
VFSImpl
::
exists
(
const
char
*
f
path
)
{
if
(
!
_mountpoint
)
{
log_e
(
"File system is not mounted"
);
return
false
;
}
VFSFileImpl
f
(
this
,
path
,
"r"
);
VFSFileImpl
f
(
this
,
f
path
,
"r"
);
if
(
f
)
{
f
.
close
();
return
true
;
...
...
@@ -115,69 +115,69 @@ bool VFSImpl::rename(const char* pathFrom, const char* pathTo)
return
rc
==
0
;
}
bool
VFSImpl
::
remove
(
const
char
*
path
)
bool
VFSImpl
::
remove
(
const
char
*
f
path
)
{
if
(
!
_mountpoint
)
{
log_e
(
"File system is not mounted"
);
return
false
;
}
if
(
!
path
||
path
[
0
]
!=
'/'
)
{
if
(
!
fpath
||
f
path
[
0
]
!=
'/'
)
{
log_e
(
"bad arguments"
);
return
false
;
}
VFSFileImpl
f
(
this
,
path
,
"r"
);
VFSFileImpl
f
(
this
,
f
path
,
"r"
);
if
(
!
f
||
f
.
isDirectory
())
{
if
(
f
)
{
f
.
close
();
}
log_e
(
"%s does not exists or is directory"
,
path
);
log_e
(
"%s does not exists or is directory"
,
f
path
);
return
false
;
}
f
.
close
();
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
path
)
+
strlen
(
_mountpoint
)
+
1
);
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
f
path
)
+
strlen
(
_mountpoint
)
+
1
);
if
(
!
temp
)
{
log_e
(
"malloc failed"
);
return
false
;
}
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
path
);
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
f
path
);
auto
rc
=
unlink
(
temp
);
free
(
temp
);
return
rc
==
0
;
}
bool
VFSImpl
::
mkdir
(
const
char
*
path
)
bool
VFSImpl
::
mkdir
(
const
char
*
f
path
)
{
if
(
!
_mountpoint
)
{
log_e
(
"File system is not mounted"
);
return
false
;
}
VFSFileImpl
f
(
this
,
path
,
"r"
);
VFSFileImpl
f
(
this
,
f
path
,
"r"
);
if
(
f
&&
f
.
isDirectory
())
{
f
.
close
();
//log_w("%s already exists", path);
//log_w("%s already exists",
f
path);
return
true
;
}
else
if
(
f
)
{
f
.
close
();
log_e
(
"%s is a file"
,
path
);
log_e
(
"%s is a file"
,
f
path
);
return
false
;
}
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
path
)
+
strlen
(
_mountpoint
)
+
1
);
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
f
path
)
+
strlen
(
_mountpoint
)
+
1
);
if
(
!
temp
)
{
log_e
(
"malloc failed"
);
return
false
;
}
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
path
);
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
f
path
);
auto
rc
=
::
mkdir
(
temp
,
ACCESSPERMS
);
free
(
temp
);
return
rc
==
0
;
}
bool
VFSImpl
::
rmdir
(
const
char
*
path
)
bool
VFSImpl
::
rmdir
(
const
char
*
f
path
)
{
if
(
!
_mountpoint
)
{
log_e
(
"File system is not mounted"
);
...
...
@@ -189,22 +189,22 @@ bool VFSImpl::rmdir(const char *path)
return
false
;
}
VFSFileImpl
f
(
this
,
path
,
"r"
);
VFSFileImpl
f
(
this
,
f
path
,
"r"
);
if
(
!
f
||
!
f
.
isDirectory
())
{
if
(
f
)
{
f
.
close
();
}
log_e
(
"%s does not exists or is a file"
,
path
);
log_e
(
"%s does not exists or is a file"
,
f
path
);
return
false
;
}
f
.
close
();
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
path
)
+
strlen
(
_mountpoint
)
+
1
);
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
f
path
)
+
strlen
(
_mountpoint
)
+
1
);
if
(
!
temp
)
{
log_e
(
"malloc failed"
);
return
false
;
}
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
path
);
sprintf
(
temp
,
"%s%s"
,
_mountpoint
,
f
path
);
auto
rc
=
::
rmdir
(
temp
);
free
(
temp
);
return
rc
==
0
;
...
...
@@ -213,7 +213,7 @@ bool VFSImpl::rmdir(const char *path)
VFSFileImpl
::
VFSFileImpl
(
VFSImpl
*
fs
,
const
char
*
path
,
const
char
*
mode
)
VFSFileImpl
::
VFSFileImpl
(
VFSImpl
*
fs
,
const
char
*
f
path
,
const
char
*
mode
)
:
_fs
(
fs
)
,
_f
(
NULL
)
,
_d
(
NULL
)
...
...
@@ -221,15 +221,15 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* path, const char* mode)
,
_isDirectory
(
false
)
,
_written
(
false
)
{
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
path
)
+
strlen
(
_fs
->
_mountpoint
)
+
1
);
char
*
temp
=
(
char
*
)
malloc
(
strlen
(
f
path
)
+
strlen
(
_fs
->
_mountpoint
)
+
1
);
if
(
!
temp
)
{
return
;
}
sprintf
(
temp
,
"%s%s"
,
_fs
->
_mountpoint
,
path
);
sprintf
(
temp
,
"%s%s"
,
_fs
->
_mountpoint
,
f
path
);
_path
=
strdup
(
path
);
_path
=
strdup
(
f
path
);
if
(
!
_path
)
{
log_e
(
"strdup(%s) failed"
,
path
);
log_e
(
"strdup(%s) failed"
,
f
path
);
free
(
temp
);
return
;
}
...
...
@@ -377,11 +377,16 @@ size_t VFSFileImpl::size() const
return
_stat
.
st_size
;
}
const
char
*
VFSFileImpl
::
name
()
const
const
char
*
VFSFileImpl
::
path
()
const
{
return
(
const
char
*
)
_path
;
}
const
char
*
VFSFileImpl
::
name
()
const
{
return
pathToFileName
(
path
());
}
//to implement
boolean
VFSFileImpl
::
isDirectory
(
void
)
{
...
...
libraries/FS/src/vfs_api.h
浏览文件 @
b6f0ba86
...
...
@@ -66,6 +66,7 @@ public:
size_t
position
()
const
override
;
size_t
size
()
const
override
;
void
close
()
override
;
const
char
*
path
()
const
override
;
const
char
*
name
()
const
override
;
time_t
getLastWrite
()
override
;
boolean
isDirectory
(
void
)
override
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录