Skip to content

Problem with SPIFFS and FS exists. #1264

Closed
@rrowe629

Description

@rrowe629

Hardware:

Board: ADAFRUIT ESP32 Feather
Core Installation/update date: 26/mar/2018
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 115200

Description:

I've been chasing a problem with ESPAsyncWebServer and serving gzipped files. I've narrowed it down to the fact that line 501 of WebResponses.cpp is never true. Here's the line:

 if(!download && !fs.exists(_path) && fs.exists(_path+".gz")){

A bit more research leads me to believe that there is a problem passing SPIFFS to the function. I constructed a sketch to test this theory, which is included below. Sure enough, when passing SPIFFS to the testSPIFFS function, I get a different result. I set Core Debug Level to "Debug", but no debug messages are displayed. I've uploaded a file called "index.html" to SPIFFS, but there is no "index.html.gz" present. Here's the output I get from my sketch:

SPIFFS.exists("/index.html") : 1
SPIFFS.exists("/index.html.gz") : 0
fs.exists("/index.html") : 1
fs.exists("/index.html.gz") : 1

SPIFFS returns the correct result, FS has a false positive on index.html.gz. This is the same behavior I am seeing in WebResponses.cpp - exists always returns true whether the file is there or not.

Sketch:

#include "SPIFFS.h"

void testSPIFFS(FS &fs, String path) {
String pathWithGz = path + ".gz";
Serial.printf("fs.exists("%s") : %d\n", path.c_str(), fs.exists(path));
Serial.printf("fs.exists("%s") : %d\n", pathWithGz.c_str(), fs.exists(pathWithGz));
}

void setup() {
Serial.begin(115200);
SPIFFS.begin();
String path = "/index.html";
String pathWithGz = path + ".gz";

Serial.printf("SPIFFS.exists("%s") : %d\n", path.c_str(), SPIFFS.exists(path));
Serial.printf("SPIFFS.exists("%s") : %d\n", pathWithGz.c_str(), SPIFFS.exists(pathWithGz));
testSPIFFS(SPIFFS, path);
}

void loop() {

}


### Debug Messages:

No additional Debug Messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions