Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

SPIFFSeditor file iterator not compatible with LittleFS  #879

Closed
@sticilface

Description

@sticilface

Probably goes without saying that the clue is in the name, but still...

I needed to modify my file iterator to be able to call recursively for directory structures. As you can see below, the files list contains a directory which the editor displays as a file.
Screenshot 2020-11-07 at 10 55 52
Screenshot 2020-11-07 at 10 55 44

I have a working fix for esp8266 that looks like this

 void _fileListIterator(FS & fs, const char * dirName, std::function<void(File & f)> Cb ); 
void SPIFFSEditor::_fileListIterator(FS & fs, const char * dirName, std::function<void(File & f)> Cb )
{
    Dir dir = fs.openDir(dirName);
    while (dir.next()) {
      if (dir.isFile()) {
        File f =  dir.openFile("r");
        if (Cb && f) {
          Cb(f); 
          f.close(); 
        }
      } else {
        _fileListIterator(fs, dir.fileName().c_str() , Cb);
      }
    }
}

and finally.. the business end changed to...

void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
  if(_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str()))
    return request->requestAuthentication();

  if(request->method() == HTTP_GET){
    if(request->hasParam("list")){
      String path = request->getParam("list")->value();
      path = String();
      String output = "[";
      _fileListIterator(_fs, path.c_str(), [&output](File &f) { 
	        if (output != "[") output += ',';
	        output += "{\"type\":\"";
	        output += "file";
	        output += "\",\"name\":\"";
	        output += String(f.fullName());
	        output += "\",\"size\":";
	        output += String(f.size());
	        output += "}";
      });
      output += "]";
      request->send(200, "application/json", output);
      output = String();
    } ...

However, I've not used SPIFFS very much with ESP32 and have not developed on it in a very long time. How different are the FS APIs and does ESP32 support LittleFS now / is planning to?

I can make a pull request, should probably change it to FSEditor as well rather than SPIFFS..

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions