espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.65k stars 7.41k forks source link

File with special characters in filname disappears using SPIFFS and LittleFS #10449

Closed TobbeG closed 1 month ago

TobbeG commented 1 month ago

Board

ESP32-S3

Device Description

Elecrow ESP32-S3 Terminal

Hardware Configuration

Nothing outside the ESP32-S3 terminal that has TFT/Touch display etc.,.

Version

latest master (checkout manually)

IDE Name

Arduino IDE 2.3.2

Operating System

Windows 11

Flash frequency

QIO 80MHz

PSRAM enabled

yes

Upload speed

921600

Description

File with specific filename disappears and is not shown in exists(filename) or able open for read It still takes up bytes from usedBytes() calling getDiskinfo directly after saving the file, lists it but after returning to loop() the same getDiskinfo does not show it

filename = "/2024-10-10_SE3.sdv" Disappears filename = "/2024_10_10_SE3.sdv" Works normal and exists and can be opened for read

Sketch

Writing to disk like this does malfunctions - file disappears

File f = FILESYSTEM.open("/2024-10-10_SE3.sdv", FILE_WRITE);
if (f) {
  f.println(s);
  f.flush();
  f.close();
  Serial.println("File created and closed.");
}
Serial.println("E2-"+getDiskInfo());

Writing to disk like this does works good - only difference is hyphens replaced by underscores

String getDiskInfo( void ) {
  File root = FILESYSTEM.open("/");
  File file = root.openNextFile();
  unsigned int n=0;
  String s=String(F("Diskinfo\r\n"));

  while (file) {
    n++;
    s += String(file.name())+String(F(" "))+String(file.size())+String(F("B\r\n"));
    file.close();
    file = root.openNextFile();
  }
  root.close();
  s += String(n) + String(F(" files total ")) + String(FILESYSTEM.usedBytes()) + String(F(" bytes of ")) + String(FILESYSTEM.totalBytes()) + String(F(" bytes available space\r\n\r\n"));
  return s;
}

Debug Message

N/A

Other Steps to Reproduce

filename /2024-01-01_SE3.sdv works fine so it seems to related to -10-10 or something similar

I have checked existing issues, online documentation and the Troubleshooting Guide

TobbeG commented 1 month ago

Tried more files created just like above, just different names 2023-10-10_SE3.sdv 276B OK 2024-10-01_SE3.sdv 276B OK 2024-10-09_SE3.sdv 276B OK 2024-10-10_SE3.sdv 276B FAILS disappears after returning to main loop() and running getDiskInfo() there

TobbeG commented 1 month ago

I have done extensive tests and i can confirm there must be an error how filenames are handled i LittleFS

/2024-10-10_SE1.sdv is overwritten when /2024-10-10_SE2.sdv is created and written

/20241010_SE1.sdv is NOT overwritten when /20241010_SE2.sdv is created and written

/2024-10-10SE1.sdv is NOT overwritten when /2024-10-10SE2.sdv is created and written

/20241010SE1.sdv is NOT overwritten when /20241010SE2.sdv is created and written

Code section used for testing: //filename.replace("-",""); //filename.replace("",""); filename.replace("","_");

    File f = FILESYSTEM.open(filename, FILE_WRITE);
    if (f){

Serial.println(filename + " opened for writing"); unsigned long l = f.println("# Date(dd.mm.yyyy) " + d + "-" + m + "-" + y + " Prices from Entsoe " + getDate(0)); l += f.print("PR;SO;YYYY;WY;WD;" + d + "." + m + "." + y); l += f.print(";" + regions[region][0] + regions[region][1] + ";" + currency[regions[region][3].toInt()]); float sum = 0.0f; String t; for (int m = 0; m < 24; m++) { t = String(prices[m], 2); t.replace('.', ','); l += f.print(";" + t); sum += prices[m]; } t = String(sum / 24, 2); t.replace('.', ','); l += f.println(";" + t); f.close(); Serial.println(filename + " closed, wrote " + String(l) + " bytes\r\n");

    }else{
      Serial.println(filename + " write failed");          
    }

Serial.println(getDiskInfo());