esp8266 / esp8266/Arduino

[request] option for "LittleFS.remove(file)" to disable auto removing empty remaining directories

Open
#8,724 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Problem Description (infos below)

in LittleFS, if i have a subdirectory with a single file and i remove it, the directory goes empty and it is ALSO removed, and ALL the empty parent directories back, RECURSIVELY... i know this is the standard behavior but is not always desirable, so searching a way to disable it by inspecting the source code (for some boolean argument, config object or something) i noticed there are none

i would like an official and everyone-available option (because i surely can modify my local source, but i don't feel is the shared spirit of opensource) to disable this auto-erase empty directories feature via a function argument, config or so... i think the fix will be easy and could have multiple options, currently i don't see any way to prevent executing this but hardcoding my source... the related source code is : https://github.com/esp8266/Arduino/blob/80bf71662551fb5e6579713dc15e541ac48ccf98/libraries/LittleFS/src/LittleFS.h#L151-L161

to ilustrate a situation when this could be annoying, imagine we have a sketch with a bash-like command line interface
```
/current/dir/> # as FS doesn't have the "current dir" concept, we maintain it in a global char[] variable
/current/dir/> ls # wrapper for LittleFS.openDir(currentDir) iteration
size file
0 myFile
- 1 object
/current/dir/> remove myFile # wrapper for remove(myFile)... but it will also remove the empty parent dirs after! (getting slower)
/current/dir/> ls # as the current dir was just deleted, a check with LittleFS.exists(currentDir) will generate an error!!
Error: path doesn't exist
/current/dir/> cd .. # back to parent dir, just slicing currentDir global var
/current/> ls # note subdir "dir" now doesn't exists as last seen, what is confusing....
size file
x blah
- (any) object(s)
/current/> # additionally, if this current dir was also emptied and deleted, "ls" would also generate another error!!
```

### Basic Infos

- [x] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [x] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.

#### Platform

|||
|-|-|
| Hardware: | ESP-12E |
| Core Version: | 3.0.2 |
| Development Env: | Arduino IDE 1.9 |
| Operating System: | Windows |

### Settings in IDE

|||
|-|-|
| Module: | NodeMCU 1.0 amica v2 compatible |
| Flash Mode: | qio, i guess (not relevant for this) |
| Flash Size: | 4MB |
| lwip Variant: | v2 Lower Memory |
| Reset Method: | nodemcu |
| Flash Frequency: | 40Mhz |
| CPU Frequency: | 80Mhz |
| Upload Using: | SERIAL |
| Upload Speed: | 115200 |

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

this is a general case about a lib function, this function will behave the same in any sketch

### Debug Messages

i haven't enabled debugging (and i tried but i couldn't.. not relevant anyway)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.