micropython / micropython/micropython
Unix port should return 4-tuples from os.ilistdir()
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 22.1k
- Forks
- 9k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 16
Description
This issue was found while working on the mpbridge solution, but is not specific to mpbridge.
File sizes are always reported as zero when using mpremote commands (ls, tree) connected to a MicroPython Unix port (via mpbridge).
II think the root cause is that the Unix port filesystem implementation returns a 3-tuple from os.ilistdir():
# Unix port returns 3-tuple: (name, type, inode)
('Jeroen_de_Vries.txt', 32768, 1326491)
# MCU returns 4-tuple: (name, type, inode, size)
('Jeroen_de_Vries.txt', 32768, 0, 267)
The optional 4th element (filesize) is missing from the Unix port, causing mpremote to misinterpret the data.
Port, board and/or hardware
Unix standard
MicroPython version
v1.27.0
Reproduction
- Start the MicroPython Unix port with mpbridge
- Use
mpremote unixto connect to the Unix port - Run directory listing commands:
mpremote unix tree -vh :remote_data/Latin_Western_European
mpremote unix ls -vh :remote_data/Latin_Western_European
Or demonstrate the root cause directly:
import os;
print(list(os.ilistdir('remote_data/Latin_Western_European')))
MCU returns 4-tuple (with filesize)
mpremote exec "import os;print(list(os.ilistdir('remote_data/Latin_Western_European')))"
Expected behaviour
File sizes should be displayed correctly, as seen when connected to an MCU:
PS D:\> mpremote tree -vh :remote_data/Latin_Western_European
tree :remote_data/Latin_Western_European
:remote_data/Latin_Western_European on COM22
├── [ 281] Arantxa_Etxeberría.txt
├── [ 311] François_Müller.txt
├── [ 248] Giuseppe_Rosé.txt
├── [ 267] Jeroen_de_Vries.txt
├── [ 311] Jordi_Puigdomènech.txt
├── [ 285] José_García.txt
├── [ 306] João_Conceição.txt
├── [ 288] O'zbek_Ismoilov.txt
├── [ 283] Xoán_Fernández.txt
├── [ 291] Ömer_Çelik.txt
└── [ 335] Đặng_Nguyễn.txt
Observed behaviour
File sizes are always reported as zero:
PS D:\> mpremote unix tree -vh :remote_data/Latin_Western_European
tree :remote_data/Latin_Western_European
:remote_data/Latin_Western_European on socket://localhost:2218
├── [ 0] Arantxa_Etxeberría.txt
├── [ 0] François_Müller.txt
├── [ 0] Giuseppe_Rosé.txt
├── [ 0] Jeroen_de_Vries.txt
├── [ 0] Jordi_Puigdomènech.txt
├── [ 0] José_García.txt
├── [ 0] João_Conceição.txt
├── [ 0] O'zbek_Ismoilov.txt
├── [ 0] Xoán_Fernández.txt
├── [ 0] Ömer_Çelik.txt
└── [ 0] Đặng_Nguyễn.txt
Additional Information
While it is documented that ilistdir() may not always return a 4-tuple , and thus may not have filesize information,
it seems to me that the unix port can provide this as the underlying filesystem clearly has that information.
https://docs.micropython.org/en/latest/library/os.html#os.ilistdir
Also note that the mpremote test suite did not capture this
Code of Conduct
Yes, I agree
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Unix port implementation of os.ilistdir() and compare its tuple construction with the MCU behavior described in the issue. Reproduce the problem with mpremote unix tree/ls and direct list(os.ilistdir(...)) calls. Done means the Unix port reports file sizes and the mpremote listings display them correctly; add coverage where appropriate because the issue notes the mpremote test suite does not currently catch this.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- cli, embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100