Related to #822
rtk ls misparses ls -la output on systems where owner/group columns contain spaces, causing
incorrect filenames and 0B sizes
Description
rtk ls currently parses the plain text output of ls -la by splitting each line on whitespace and
assuming fixed column positions.
That assumption breaks on systems where the owner or group field contains spaces. In that case,
the columns shift, so RTK reads the wrong token as the file size and also reconstructs the
filename incorrectly.
As a result:
- some files are shown with a size of 0B even when they are not empty
- some entry names include trailing date/time fragments such as 31 16:18
- directory/file names can be corrupted in the compact output
Current implementation
In dev/projets/rtk/src/cmds/system/ls.rs:162, the code does:
- split each ls -la line with split_whitespace()
- assume parts[4] is the size
- assume parts[8..] is the filename
This is fragile because ls output is not a stable machine-readable format.
Relevant lines:
- dev/projets/rtk/src/cmds/system/ls.rs:162
- dev/projets/rtk/src/cmds/system/ls.rs:167
- dev/projets/rtk/src/cmds/system/ls.rs:185
Environment where reproduced
On this machine, ls -la shows a group name with spaces, for example:
-rw-r--r-- 1 fjeanne utilisa. du domaine 0 Mar 31 16:18 empty.txt
RTK output for the same directory becomes:
31 16:18 empty.txt 0B
This demonstrates that the parser is consuming part of the date/time as part of the filename and
defaulting the size to 0.
Steps to reproduce
- Use a system where the owner or group name contains spaces in ls -la output.
- Create a test directory with at least one file.
- Run ls -la .
- Run rtk ls .
Related to #822
rtk ls misparses ls -la output on systems where owner/group columns contain spaces, causing
incorrect filenames and 0B sizes
Description
rtk ls currently parses the plain text output of ls -la by splitting each line on whitespace and
assuming fixed column positions.
That assumption breaks on systems where the owner or group field contains spaces. In that case,
the columns shift, so RTK reads the wrong token as the file size and also reconstructs the
filename incorrectly.
As a result:
Current implementation
In dev/projets/rtk/src/cmds/system/ls.rs:162, the code does:
This is fragile because ls output is not a stable machine-readable format.
Relevant lines:
Environment where reproduced
On this machine, ls -la shows a group name with spaces, for example:
-rw-r--r-- 1 fjeanne utilisa. du domaine 0 Mar 31 16:18 empty.txt
RTK output for the same directory becomes:
31 16:18 empty.txt 0B
This demonstrates that the parser is consuming part of the date/time as part of the filename and
defaulting the size to 0.
Steps to reproduce