Skip to content

Unix port should return 4-tuples from os.ilistdir() #18661

@Josverl

Description

@Josverl

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

  1. Start the MicroPython Unix port with mpbridge
  2. Use mpremote unix to connect to the Unix port
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementationsport-unix

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions