Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LittleFS - writing empty file shows "- write failed" when in fact the file was written correctly #10556

Open
1 task done
rFlightFPV opened this issue Nov 2, 2024 · 1 comment
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@rFlightFPV
Copy link

rFlightFPV commented Nov 2, 2024

Board

LilyGo ESP32 T-SIM7080G

Device Description

No additional hardware

Hardware Configuration

No

Version

v3.0.6

IDE Name

Arduino IDE 2.3.3

Operating System

MacOS Sequoia 15.1

Flash frequency

240 MHz

PSRAM enabled

yes

Upload speed

460800

Description

Using LittleFS included in core and examples provided in this repository. I am using a webserver form where the user can populate a field or leave it empty. It works fine writing and reading files. LittleFS seems to be perfectly capable of writing empty files, the file is written and is listed when reading the directory (see below) with size:0. However when writing the file, the Serial printout is " -write failed" which is not true. I know it is minor issue as it's just an error in printout handling as far as I understand. Still it can be irritating while debugging.

Sketch

// write file to LittleFS
void writeFile(fs::FS &fs, const char * path, const char * message){
  Serial.printf("Writing file: %s\r\n", path);

  File file = fs.open(path, FILE_WRITE);
  if(!file){
    Serial.println("- failed to open file for writing");
    return;
  }
  if(file.print(message)){
    Serial.println("- file written");
  } else {
    Serial.println("- write failed");
  }
}

Debug Message

12:18:45.292 -> Writing file: /test.txt
12:18:45.292 -> - write failed
.
13:04:04.056 -> Listing directory: /
13:04:04.056 ->   FILE: test.txt	SIZE: 0
.
13:04:04.185 -> Reading file: /test.txt

Other Steps to Reproduce

No response

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@rFlightFPV rFlightFPV added the Status: Awaiting triage Issue is waiting for triage label Nov 2, 2024
@P-R-O-C-H-Y
Copy link
Member

Hi @rFlightFPV, I have checked the code and if size of the message is 0 -> no message, write returns 0.
From my point of view the approach is fine, as you can't write "nothing". Maybe you can add a check in the sketch, to not try to write when there is nothing to write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants