spiffs: follow symlinks in host test
This commit is contained in:
parent
6153a0ab62
commit
a986283997
|
@ -87,7 +87,11 @@ $(TEST_PROGRAM): lib $(TEST_OBJ_FILES) $(SPI_FLASH_SIM_BUILD_DIR)/$(SPI_FLASH_SI
|
||||||
|
|
||||||
# Use spiffs source directory as the test image
|
# Use spiffs source directory as the test image
|
||||||
spiffs_image: ../spiffs $(shell find ../spiffs -type d) $(shell find ../spiffs -type -f -name '*')
|
spiffs_image: ../spiffs $(shell find ../spiffs -type d) $(shell find ../spiffs -type -f -name '*')
|
||||||
../spiffsgen.py 2097152 ../spiffs image.bin
|
# Creation of test symlinks unfortunately causes rerun of spiffsgen.py every make invoke
|
||||||
|
rm -f ../spiffs/include ../spiffs/CMakeLists.txt
|
||||||
|
ln -s ../include ../spiffs/include
|
||||||
|
ln -s ../CMakeLists.txt ../spiffs/CMakeLists.txt
|
||||||
|
../spiffsgen.py --follow-symlinks 2097152 ../spiffs image.bin
|
||||||
|
|
||||||
test: $(TEST_PROGRAM) spiffs_image
|
test: $(TEST_PROGRAM) spiffs_image
|
||||||
./$(TEST_PROGRAM)
|
./$(TEST_PROGRAM)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
#include "spiffs.h"
|
#include "spiffs.h"
|
||||||
|
@ -96,7 +100,18 @@ static void check_spiffs_files(spiffs *fs, const char *base_path, char* cur_path
|
||||||
|
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
char *name = entry->d_name;
|
char *name = entry->d_name;
|
||||||
if (entry->d_type == DT_DIR) {
|
|
||||||
|
char path[PATH_MAX] = { 0 };
|
||||||
|
|
||||||
|
// Read the file from host FS
|
||||||
|
strcpy(path, cur_path);
|
||||||
|
strcat(path, "/");
|
||||||
|
strcat(path, name);
|
||||||
|
|
||||||
|
struct stat sb;
|
||||||
|
stat(path, &sb);
|
||||||
|
|
||||||
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
||||||
continue;
|
continue;
|
||||||
cur_path[len] = '/';
|
cur_path[len] = '/';
|
||||||
|
@ -104,13 +119,6 @@ static void check_spiffs_files(spiffs *fs, const char *base_path, char* cur_path
|
||||||
check_spiffs_files(fs, base_path, cur_path);
|
check_spiffs_files(fs, base_path, cur_path);
|
||||||
cur_path[len] = '\0';
|
cur_path[len] = '\0';
|
||||||
} else {
|
} else {
|
||||||
char path[PATH_MAX];
|
|
||||||
|
|
||||||
// Read the file from host FS
|
|
||||||
strcpy(path, cur_path);
|
|
||||||
strcat(path, "/");
|
|
||||||
strcat(path, name);
|
|
||||||
|
|
||||||
FILE* f = fopen(path , "r");
|
FILE* f = fopen(path , "r");
|
||||||
REQUIRE(f);
|
REQUIRE(f);
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
|
@ -126,6 +134,7 @@ static void check_spiffs_files(spiffs *fs, const char *base_path, char* cur_path
|
||||||
// Read the file from SPIFFS
|
// Read the file from SPIFFS
|
||||||
char *spiffs_path = path + strlen(base_path);
|
char *spiffs_path = path + strlen(base_path);
|
||||||
spiffs_res = SPIFFS_open(fs, spiffs_path, SPIFFS_RDONLY, 0);
|
spiffs_res = SPIFFS_open(fs, spiffs_path, SPIFFS_RDONLY, 0);
|
||||||
|
|
||||||
REQUIRE(spiffs_res > SPIFFS_OK);
|
REQUIRE(spiffs_res > SPIFFS_OK);
|
||||||
|
|
||||||
spiffs_file fd = spiffs_res;
|
spiffs_file fd = spiffs_res;
|
||||||
|
|
Loading…
Reference in a new issue