mirror of
https://github.com/janet-lang/janet
synced 2025-01-23 13:46:52 +00:00
Add testing for making and removing directory.
This commit is contained in:
parent
aee077c1bd
commit
f7c90bc1ff
@ -2411,8 +2411,17 @@ JANET_CORE_FN(os_dir,
|
|||||||
/* Read directory items with opendir / readdir / closedir */
|
/* Read directory items with opendir / readdir / closedir */
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
DIR *dfd = opendir(dir);
|
DIR *dfd = opendir(dir);
|
||||||
if (dfd == NULL) janet_panicf("cannot open directory %s", dir);
|
if (dfd == NULL) janet_panicf("cannot open directory %s: %s", dir, janet_strerror(errno));
|
||||||
while ((dp = readdir(dfd)) != NULL) {
|
for (;;) {
|
||||||
|
errno = 0;
|
||||||
|
dp = readdir(dfd);
|
||||||
|
if (dp == NULL) {
|
||||||
|
if (errno) {
|
||||||
|
closedir(dfd);
|
||||||
|
janet_panicf("failed to read directory %s: %s", dir, janet_strerror(errno));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
|
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,9 @@
|
|||||||
(os/rm x))
|
(os/rm x))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
# Test mkdir -> rmdir
|
||||||
|
(assert (os/mkdir "./tempdir123"))
|
||||||
|
(rmrf "./tempdir123")
|
||||||
|
|
||||||
# Setup a temporary syspath for manipultation
|
# Setup a temporary syspath for manipultation
|
||||||
(math/seedrandom (os/cryptorand 16))
|
(math/seedrandom (os/cryptorand 16))
|
||||||
|
Loading…
Reference in New Issue
Block a user