Skip to content

enforce LC_ALL=C for ls, fix #1715#1716

Open
yangjuncode wants to merge 1 commit intortk-ai:masterfrom
yangjuncode:enforce-locale=c-for-ls
Open

enforce LC_ALL=C for ls, fix #1715#1716
yangjuncode wants to merge 1 commit intortk-ai:masterfrom
yangjuncode:enforce-locale=c-for-ls

Conversation

@yangjuncode
Copy link
Copy Markdown

@yangjuncode yangjuncode commented May 5, 2026

enforce LC_ALL=C for ls, fix #1715

RTK ls Locale Bug — Root Cause Analysis

Symptom

  • ls shows normal directory output
  • rtk ls returns (empty) even when the directory contains files

Root Cause

RTK's ls parser relies on a date regex that only matches English month names (@src/cmds/system/ls.rs:15-18):

static ref LS_DATE_RE: Regex = Regex::new(
    r"\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{1,2}\s+(?:\d{4}|\d{2}:\d{2})\s+"
).unwrap();

This regex is used in parse_ls_line() (@ls.rs:124) to anchor the line and extract the filename:

fn parse_ls_line(line: &str) -> Option<(char, u64, String)> {
    let date_match = LS_DATE_RE.find(line)?;  // Returns None for non-English months
    let name = line[date_match.end()..].to_string();
    // ...
}

When the system locale is non-English (e.g., Chinese zh_CN.UTF-8), ls -la outputs localized month names:

# English locale (C)
-rw-r--r-- 1 user staff 1234 May  5 12:00 file.txt

# Chinese locale (zh_CN.UTF-8)
-rw-r--r-- 1 user staff 1234  5月  5 12:00 file.txt

The regex fails to match 5月 (or any non-English month), so parse_ls_line() returns None for every line. All lines are skipped by continue in compact_ls() (@ls.rs:166). With zero directories and zero files parsed, the function falls into the empty case (@ls.rs:193-195):

if dirs.is_empty() && files.is_empty() {
    return ("(empty)\n".to_string(), String::new());
}

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 5, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk ls return (empty) if locale is not C

2 participants