Skip to content

LittleFS.exists() is giving an error #7615

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

Closed
1 task done
Adrianotiger opened this issue Dec 22, 2022 · 6 comments · Fixed by #10217
Closed
1 task done

LittleFS.exists() is giving an error #7615

Adrianotiger opened this issue Dec 22, 2022 · 6 comments · Fixed by #10217
Labels
Status: In Progress ⚠️ Issue is in progress
Milestone

Comments

@Adrianotiger
Copy link

Board

ESP32-S3

Device Description

ESP32-S3 16MB Dev-Kit

Hardware Configuration

Nothing

Version

v2.0.5

IDE Name

Arduino IDE 2.0.4

Operating System

Windows 10

Flash frequency

240MHz

PSRAM enabled

no

Upload speed

115200

Description

I am using the LittleFS library.
When I try to check if a file exists, this function is executed:

bool LittleFSImpl::exists(const char* path)

bool LittleFSImpl::exists(const char* path)
{
    File f = open(path, "r",false);
    return (f == true);
}

As it try to open a file, I get this error:
[E][vfs_api.cpp:104] open(): /littlefs/g00000/c001 does not exist, no permits for creation

From this line:

log_e("%s does not exist, no permits for creation", temp);

I think this error should not be logged, if we just check if a file exists.

Sketch

char path[20];
createPath(path);  
if(!LittleFS.exists(path))
{
  LittleFS.mkdir(path);
}

Debug Message

[E][vfs_api.cpp:104] open(): /littlefs/g00000/c001 does not exist, no permits for creation

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.
@Adrianotiger Adrianotiger added the Status: Awaiting triage Issue is waiting for triage label Dec 22, 2022
@Adrianotiger Adrianotiger changed the title exists() is giving an error LittleFS.exists() is giving an error Dec 22, 2022
@mrengineer7777
Copy link
Collaborator

mrengineer7777 commented Dec 22, 2022

I agree. The message should be at info, debug, or verbose log level. However it's not that simple. exists() actually calls open() on the file (and then closes it) with read only permission, no create flag. In your case you are looking at a directory, so the solution is slightly different.

Workaround: use LittleFS.mkdir(path) instead of exists(). It will create the directory if it doesn't exist. Otherwise it just returns true. See bool VFSImpl::mkdir(const char *fpath) in vfs_api.cpp.

@Adrianotiger
Copy link
Author

I believe you that's not that simple :)

But even as info or verbose, this is a wrong info: "XXX does not exist, no permits for creation". As I don't want create a file at this point of the code.

Rewrite the open function inside the exists functions is not a solution.

Maybe with a new argument with __builtin_FUNCTION() as parameter but it is probably also bad, for just a debug output.

Maybe opening the file with the exists mode?

@Anx2k
Copy link
Contributor

Anx2k commented Dec 27, 2022

I encountered this same issue, and instead of using their exists function I just use the normal sys/stat.h stat() function - it will return whether a file/directory exists or not, and won't print that error. This actually works for SD cards as well as a bonus.

@OttoKlaasen
Copy link

I have the same issue when i do a LittleFS.exist on an empty directory
It will show an error in the serial.
The code itself works fine.

Code snippet example:

  if (LittleFS.exists(FILE_PHOTO)) {
       //Returns true if a file with a given path exists; false otherwise.
       if(LittleFS.remove(FILE_PHOTO)) {
          //Deletes the file given its absolute path. Returns true if the file was deleted successfully.
           Serial.printf("FILE DELETED: %s\n", FILE_PHOTO);
       } else {
            Serial.println("ERROR WHILE DELETE FILE");
   }
  }
  delay(1000);   // Wait for it
  // Open dir folder
  dir = LittleFS.open("/");
  // Cycle all the content
  printDirectory(dir);
  Serial.println("Close dir connection.");
  dir.close();
  
  // next will call an error: [ 30214][E][vfs_api.cpp:105] open(): /littlefs/photo.jpg does not exist, no permits for creation
  // I will ignore the error as the code seems to work.
  bool FileExist = LittleFS.exists(FILE_PHOTO);

  if(!FileExist){
      Serial.println("FILE DOES NOT EXIST, so we can CREATE and WRITE to file..............");      
      file = LittleFS.open(FILE_PHOTO, FILE_WRITE);

@BlueAndi
Copy link
Contributor

BlueAndi commented Apr 16, 2023

In my use case I avoid checking first with exists() and if yes, use open() to load it because of performance. I use always open() and check whether I got the file or not. My recommendation is to only show it in verbose mode.

@hsaturn
Copy link

hsaturn commented May 27, 2023

I agree. The message should be at info, debug, or verbose log level. However it's not that simple. exists() actually calls open() on the file (and then closes it) with read only permission, no create flag. In your case you are looking at a directory, so the solution is slightly different.

Workaround: use LittleFS.mkdir(path) instead of exists(). It will create the directory if it doesn't exist. Otherwise it just returns true. See bool VFSImpl::mkdir(const char *fpath) in vfs_api.cpp.

This is not an answer. The library MUST not log in that case. I have the same problem, and I'm using the com port.
I tried many solutions to disable log with no success. And even with success, this would have been a workaround.
My roomba do not like at all receiving garbage through the serial port when I check for file existency !!!
LittleFS has to be fixed.

And technically:

  • adding a parameter with default to open() is a solution
  • using stat instead of open in exists is a solution
  • reversing logic: open uses exists then opens instead of exists uses open then closes is a solution
  • using a 'special mode' (nullptr, '*' etc) is one more solution
  • other solutions for sure exists

Don't say that it's not that simple. It is ! Lazyness is not a solution !

And finally a workaround for this problem
build_flags = -DCORE_DEBUG_LEVEL=0

No log at all.

benaveld added a commit to Qvantum-Energy/arduino-esp32 that referenced this issue May 16, 2024
All it dose is clog the log when calling VFSImpl::exists.
Related to <espressif#7615>
BlueAndi added a commit to BlueAndi/arduino-esp32 that referenced this issue Aug 21, 2024
…whether the file exists, because open() will log an error which is confusing, but might be relevant in case a developer uses open() and expects that the file is there.

espressif#7615
BlueAndi added a commit to BlueAndi/arduino-esp32 that referenced this issue Aug 21, 2024
Use exists() from VFSImpl base class and avoid using open() to check whether the file exists, because open() will log an error which is confusing, but might be relevant in case a developer uses open() and expects that the file is there.
espressif#7615
BlueAndi added a commit to BlueAndi/arduino-esp32 that referenced this issue Aug 21, 2024
Use exists() from VFSImpl base class and avoid using open() to check whether the file exists, because open() will log an error which is confusing, but might be relevant in case a developer uses open() and expects that the file is there.
espressif#7615
@VojtechBartoska VojtechBartoska added this to the 3.0.5 milestone Aug 28, 2024
@VojtechBartoska VojtechBartoska added Status: In Progress ⚠️ Issue is in progress and removed Status: Awaiting triage Issue is waiting for triage labels Aug 28, 2024
benaveld added a commit to Qvantum-Energy/arduino-esp32 that referenced this issue Nov 14, 2024
All it dose is clog the log when calling VFSImpl::exists.
Related to <espressif#7615>
benaveld added a commit to Qvantum-Energy/arduino-esp32 that referenced this issue Dec 5, 2024
All it dose is clog the log when calling VFSImpl::exists.
Related to <espressif#7615>
benaveld added a commit to Qvantum-Energy/arduino-esp32 that referenced this issue Feb 5, 2025
All it dose is clog the log when calling VFSImpl::exists.
Related to <espressif#7615>
benaveld added a commit to Qvantum-Energy/arduino-esp32 that referenced this issue Apr 2, 2025
All it dose is clog the log when calling VFSImpl::exists.
Related to <espressif#7615>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress ⚠️ Issue is in progress
Projects
Development

Successfully merging a pull request may close this issue.

7 participants