Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
d02f3a57
Commit
d02f3a57
authored
Sep 28, 2016
by
Alex March
Committed by
Damien George
Oct 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/vfs_fat: Add file and directory checks for remove and rmdir.
parent
eaef6b53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
10 deletions
+29
-10
extmod/vfs_fat.c
extmod/vfs_fat.c
+29
-10
No files found.
extmod/vfs_fat.c
View file @
d02f3a57
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include <string.h>
#include <string.h>
#include "py/nlr.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "lib/fatfs/ff.h"
#include "lib/fatfs/ff.h"
#include "lib/fatfs/diskio.h"
#include "lib/fatfs/diskio.h"
#include "extmod/vfs_fat_file.h"
#include "extmod/vfs_fat_file.h"
...
@@ -76,24 +77,42 @@ STATIC mp_obj_t fat_vfs_listdir_func(size_t n_args, const mp_obj_t *args) {
...
@@ -76,24 +77,42 @@ STATIC mp_obj_t fat_vfs_listdir_func(size_t n_args, const mp_obj_t *args) {
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
fat_vfs_listdir_obj
,
1
,
2
,
fat_vfs_listdir_func
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
fat_vfs_listdir_obj
,
1
,
2
,
fat_vfs_listdir_func
);
STATIC
mp_obj_t
fat_vfs_remove
(
mp_obj_t
vfs_in
,
mp_obj_t
path_in
)
{
STATIC
mp_obj_t
fat_vfs_remove_internal
(
mp_obj_t
path_in
,
mp_int_t
attr
)
{
(
void
)
vfs_in
;
const
char
*
path
=
mp_obj_str_get_str
(
path_in
);
const
char
*
path
=
mp_obj_str_get_str
(
path_in
);
// TODO check that path is actually a file before trying to unlink it
FRESULT
res
=
f_unlink
(
path
);
FILINFO
fno
;
if
(
res
==
FR_OK
)
{
#if _USE_LFN
fno
.
lfname
=
NULL
;
fno
.
lfsize
=
0
;
#endif
FRESULT
res
=
f_stat
(
path
,
&
fno
);
if
(
res
!=
FR_OK
)
{
mp_raise_OSError
(
fresult_to_errno_table
[
res
]);
}
// check if path is a file or directory
if
((
fno
.
fattrib
&
AM_DIR
)
==
attr
)
{
res
=
f_unlink
(
path
);
if
(
res
!=
FR_OK
)
{
mp_raise_OSError
(
fresult_to_errno_table
[
res
]);
}
return
mp_const_none
;
return
mp_const_none
;
}
else
{
}
else
{
mp_raise_OSError
(
fresult_to_errno_table
[
res
]
);
mp_raise_OSError
(
attr
?
MP_ENOTDIR
:
MP_EISDIR
);
}
}
}
}
STATIC
mp_obj_t
fat_vfs_remove
(
mp_obj_t
vfs_in
,
mp_obj_t
path_in
)
{
(
void
)
vfs_in
;
return
fat_vfs_remove_internal
(
path_in
,
0
);
// 0 == file attribute
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
fat_vfs_remove_obj
,
fat_vfs_remove
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
fat_vfs_remove_obj
,
fat_vfs_remove
);
STATIC
mp_obj_t
fat_vfs_rmdir
(
mp_obj_t
vfs_in
,
mp_obj_t
path_in
)
{
STATIC
mp_obj_t
fat_vfs_rmdir
(
mp_obj_t
vfs_in
,
mp_obj_t
path_in
)
{
// TODO: Currently just redirects to fat_vfs_remove(), which are
(
void
)
vfs_in
;
// backed by the same underlying FatFs function. Should at least
return
fat_vfs_remove_internal
(
path_in
,
AM_DIR
);
// check that path is actually a dir.
return
fat_vfs_remove
(
vfs_in
,
path_in
);
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
fat_vfs_rmdir_obj
,
fat_vfs_rmdir
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
fat_vfs_rmdir_obj
,
fat_vfs_rmdir
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment