Skip to content

Commit 680a78b

Browse files
committed
fix(volume): handle european decimal commas in parse_size_string and pin df locale to C
1 parent 6dfeccf commit 680a78b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

core/src/volume/platform/linux.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub async fn detect_volumes(
3333

3434
// Use df to get mounted filesystems
3535
let output = Command::new("df")
36+
.env("LC_ALL", "C")
3637
.args(["-h", "-T"]) // -T shows filesystem type
3738
.output()
3839
.map_err(|e| VolumeError::platform(format!("Failed to run df: {}", e)))?;

core/src/volume/utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ pub fn parse_size_string(size_str: &str) -> VolumeResult<u64> {
2222
return Ok(0);
2323
}
2424

25-
let size_str = size_str.replace(",", ""); // Remove commas
25+
let size_str = if size_str.contains(',') && !size_str.contains('.') {
26+
size_str.replace(',', ".")
27+
} else {
28+
size_str.replace(',', "")
29+
};
2630
let (number_part, unit) = if let Some(pos) = size_str.find(char::is_alphabetic) {
2731
(&size_str[..pos], &size_str[pos..])
2832
} else {
@@ -336,6 +340,10 @@ mod tests {
336340
parse_size_string("1.5G").unwrap(),
337341
(1.5 * 1024.0 * 1024.0 * 1024.0) as u64
338342
);
343+
assert_eq!(
344+
parse_size_string("1,5G").unwrap(),
345+
(1.5 * 1024.0 * 1024.0 * 1024.0) as u64
346+
);
339347
assert_eq!(parse_size_string("-").unwrap(), 0);
340348
}
341349

0 commit comments

Comments
 (0)