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 unix to 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
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
mpremotecommands (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():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
mpremote unixto connect to the Unix portOr demonstrate the root cause directly:
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:
Observed behaviour
File sizes are always reported as zero:
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